Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
VideoLAN
medialibrary
Commits
e5b274e8
Commit
e5b274e8
authored
Dec 15, 2015
by
Hugo Beauzée-Luyssen
Browse files
s/Mountpoint/Device
parent
a8f82d12
Changes
16
Hide whitespace changes
Inline
Side-by-side
include/factory/IFileSystem.h
View file @
e5b274e8
...
...
@@ -29,7 +29,7 @@ namespace fs
{
class
IDirectory
;
class
IFile
;
class
I
Mountpoint
;
class
I
Device
;
}
namespace
factory
...
...
include/filesystem/I
Mountpoint
.h
→
include/filesystem/I
Device
.h
View file @
e5b274e8
...
...
@@ -26,10 +26,10 @@
namespace
fs
{
class
I
Mountpoint
class
I
Device
{
public:
virtual
~
I
Mountpoint
()
=
default
;
virtual
~
I
Device
()
=
default
;
virtual
const
std
::
string
&
uuid
()
const
=
0
;
virtual
bool
isPresent
()
const
=
0
;
virtual
bool
isRemovable
()
const
=
0
;
...
...
include/filesystem/IDirectory.h
View file @
e5b274e8
...
...
@@ -29,7 +29,7 @@
namespace
fs
{
class
IFile
;
class
I
Mountpoint
;
class
I
Device
;
class
IDirectory
{
...
...
@@ -42,7 +42,7 @@ namespace fs
/// Returns a list of absolute path to this folder subdirectories
virtual
const
std
::
vector
<
std
::
string
>&
dirs
()
=
0
;
virtual
unsigned
int
lastModificationDate
()
const
=
0
;
virtual
std
::
shared_ptr
<
I
Mountpoint
>
mountpoint
()
const
=
0
;
virtual
std
::
shared_ptr
<
I
Device
>
device
()
const
=
0
;
virtual
bool
isRemovable
()
const
=
0
;
};
}
src/CMakeLists.txt
View file @
e5b274e8
...
...
@@ -66,13 +66,13 @@ list(APPEND SRC_LIST ${HEADERS_LIST}
Parser.cpp
Artist.cpp
Settings.cpp
Mountpoint
.cpp
Device
.cpp
factory/FileSystem.cpp
filesystem/common/CommonFile.cpp
filesystem/
${
ARCH_FOLDER
}
/Directory.cpp
filesystem/
${
ARCH_FOLDER
}
/File.cpp
filesystem/
${
ARCH_FOLDER
}
/
Mountpoint
.cpp
filesystem/
${
ARCH_FOLDER
}
/
Device
.cpp
discoverer/FsDiscoverer.cpp
discoverer/DiscovererWorker.cpp
...
...
src/
Mountpoint
.cpp
→
src/
Device
.cpp
View file @
e5b274e8
...
...
@@ -20,13 +20,13 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include
"
Mountpoint
.h"
#include
"
Device
.h"
const
std
::
string
policy
::
Mountpoint
Table
::
Name
=
"
Mountpoint
"
;
const
std
::
string
policy
::
Mountpoint
Table
::
PrimaryKeyColumn
=
"id_
mountpoint
"
;
unsigned
int
Mountpoint
::*
const
policy
::
Mountpoint
Table
::
PrimaryKey
=
&
Mountpoint
::
m_id
;
const
std
::
string
policy
::
Device
Table
::
Name
=
"
Device
"
;
const
std
::
string
policy
::
Device
Table
::
PrimaryKeyColumn
=
"id_
device
"
;
unsigned
int
Device
::*
const
policy
::
Device
Table
::
PrimaryKey
=
&
Device
::
m_id
;
Mountpoint
::
Mountpoint
(
DBConnection
dbConnection
,
sqlite
::
Row
&
row
)
Device
::
Device
(
DBConnection
dbConnection
,
sqlite
::
Row
&
row
)
:
m_dbConn
(
dbConnection
)
{
row
>>
m_id
...
...
@@ -37,58 +37,58 @@ Mountpoint::Mountpoint( DBConnection dbConnection, sqlite::Row& row )
//only be here for sqlite triggering purposes
}
Mountpoint
::
Mountpoint
(
const
std
::
string
&
uuid
,
bool
isRemovable
)
Device
::
Device
(
const
std
::
string
&
uuid
,
bool
isRemovable
)
:
m_uuid
(
uuid
)
,
m_isRemovable
(
isRemovable
)
// Assume we can't add an
unmounted/absent mountpoint
// Assume we can't add an
absent device
,
m_isPresent
(
true
)
{
}
unsigned
int
Mountpoint
::
id
()
const
unsigned
int
Device
::
id
()
const
{
return
m_id
;
}
const
std
::
string
&
Mountpoint
::
uuid
()
const
const
std
::
string
&
Device
::
uuid
()
const
{
return
m_uuid
;
}
bool
Mountpoint
::
isRemovable
()
const
bool
Device
::
isRemovable
()
const
{
return
m_isRemovable
;
}
bool
Mountpoint
::
isPresent
()
const
bool
Device
::
isPresent
()
const
{
return
m_isPresent
;
}
void
Mountpoint
::
setPresent
(
bool
value
)
void
Device
::
setPresent
(
bool
value
)
{
static
const
std
::
string
req
=
"UPDATE "
+
policy
::
Mountpoint
Table
::
Name
+
static
const
std
::
string
req
=
"UPDATE "
+
policy
::
Device
Table
::
Name
+
" SET is_present = ?"
;
if
(
sqlite
::
Tools
::
executeUpdate
(
m_dbConn
,
req
,
value
)
==
false
)
return
;
m_isPresent
=
value
;
}
std
::
shared_ptr
<
Mountpoint
>
Mountpoint
::
create
(
DBConnection
dbConnection
,
const
std
::
string
&
uuid
,
bool
isRemovable
)
std
::
shared_ptr
<
Device
>
Device
::
create
(
DBConnection
dbConnection
,
const
std
::
string
&
uuid
,
bool
isRemovable
)
{
static
const
std
::
string
req
=
"INSERT INTO "
+
policy
::
Mountpoint
Table
::
Name
static
const
std
::
string
req
=
"INSERT INTO "
+
policy
::
Device
Table
::
Name
+
"(uuid, is_removable, is_present) VALUES(?, ?, ?)"
;
auto
self
=
std
::
make_shared
<
Mountpoint
>
(
uuid
,
isRemovable
);
auto
self
=
std
::
make_shared
<
Device
>
(
uuid
,
isRemovable
);
if
(
insert
(
dbConnection
,
self
,
req
,
uuid
,
isRemovable
,
self
->
isPresent
()
)
==
false
)
return
nullptr
;
self
->
m_dbConn
=
dbConnection
;
return
self
;
}
bool
Mountpoint
::
createTable
(
DBConnection
connection
)
bool
Device
::
createTable
(
DBConnection
connection
)
{
std
::
string
req
=
"CREATE TABLE IF NOT EXISTS "
+
policy
::
Mountpoint
Table
::
Name
+
"("
"id_
mountpoint
INTEGER PRIMARY KEY AUTOINCREMENT,"
std
::
string
req
=
"CREATE TABLE IF NOT EXISTS "
+
policy
::
Device
Table
::
Name
+
"("
"id_
device
INTEGER PRIMARY KEY AUTOINCREMENT,"
"uuid TEXT UNIQUE ON CONFLICT FAIL,"
"is_removable BOOLEAN,"
"is_present BOOLEAN"
...
...
@@ -96,9 +96,9 @@ bool Mountpoint::createTable(DBConnection connection)
return
sqlite
::
Tools
::
executeRequest
(
connection
,
req
);
}
std
::
shared_ptr
<
Mountpoint
>
Mountpoint
::
fromUuid
(
DBConnection
dbConnection
,
const
std
::
string
&
uuid
)
std
::
shared_ptr
<
Device
>
Device
::
fromUuid
(
DBConnection
dbConnection
,
const
std
::
string
&
uuid
)
{
static
const
std
::
string
req
=
"SELECT * FROM "
+
policy
::
Mountpoint
Table
::
Name
+
static
const
std
::
string
req
=
"SELECT * FROM "
+
policy
::
Device
Table
::
Name
+
" WHERE uuid = ?"
;
return
fetch
(
dbConnection
,
req
,
uuid
);
}
...
...
src/
Mountpoint
.h
→
src/
Device
.h
View file @
e5b274e8
...
...
@@ -25,32 +25,32 @@
#include
"Types.h"
#include
"database/DatabaseHelpers.h"
class
Mountpoint
;
class
Device
;
namespace
policy
{
struct
Mountpoint
Table
struct
Device
Table
{
static
const
std
::
string
Name
;
static
const
std
::
string
PrimaryKeyColumn
;
static
unsigned
int
Mountpoint
::*
const
PrimaryKey
;
static
unsigned
int
Device
::*
const
PrimaryKey
;
};
}
class
Mountpoint
:
public
DatabaseHelpers
<
Mountpoint
,
policy
::
Mountpoint
Table
>
class
Device
:
public
DatabaseHelpers
<
Device
,
policy
::
Device
Table
>
{
public:
Mountpoint
(
const
std
::
string
&
uuid
,
bool
isRemovable
);
Mountpoint
(
DBConnection
dbConnection
,
sqlite
::
Row
&
row
);
Device
(
const
std
::
string
&
uuid
,
bool
isRemovable
);
Device
(
DBConnection
dbConnection
,
sqlite
::
Row
&
row
);
unsigned
int
id
()
const
;
const
std
::
string
&
uuid
()
const
;
bool
isRemovable
()
const
;
bool
isPresent
()
const
;
void
setPresent
(
bool
value
);
static
std
::
shared_ptr
<
Mountpoint
>
create
(
DBConnection
dbConnection
,
const
std
::
string
&
uuid
,
bool
isRemovable
);
static
std
::
shared_ptr
<
Device
>
create
(
DBConnection
dbConnection
,
const
std
::
string
&
uuid
,
bool
isRemovable
);
static
bool
createTable
(
DBConnection
connection
);
static
std
::
shared_ptr
<
Mountpoint
>
fromUuid
(
DBConnection
dbConnection
,
const
std
::
string
&
uuid
);
static
std
::
shared_ptr
<
Device
>
fromUuid
(
DBConnection
dbConnection
,
const
std
::
string
&
uuid
);
private:
DBConnection
m_dbConn
;
...
...
@@ -62,5 +62,5 @@ private:
bool
m_isRemovable
;
bool
m_isPresent
;
friend
struct
policy
::
Mountpoint
Table
;
friend
struct
policy
::
Device
Table
;
};
src/MediaLibrary.cpp
View file @
e5b274e8
...
...
@@ -31,7 +31,7 @@
#include
"AudioTrack.h"
#include
"discoverer/DiscovererWorker.h"
#include
"Media.h"
#include
"
Mountpoint
.h"
#include
"
Device
.h"
#include
"Folder.h"
#include
"MediaLibrary.h"
#include
"IMetadataService.h"
...
...
@@ -99,7 +99,7 @@ MediaLibrary::~MediaLibrary()
VideoTrack
::
clear
();
AudioTrack
::
clear
();
Artist
::
clear
();
Mountpoint
::
clear
();
Device
::
clear
();
// Explicitely release the connection's TLS
if
(
m_dbConnection
!=
nullptr
)
m_dbConnection
->
release
();
...
...
@@ -156,7 +156,7 @@ bool MediaLibrary::initialize( const std::string& dbPath, const std::string& sna
Artist
::
createTable
(
m_dbConnection
.
get
()
)
&&
Artist
::
createDefaultArtists
(
m_dbConnection
.
get
()
)
&&
Settings
::
createTable
(
m_dbConnection
.
get
()
)
&&
Mountpoint
::
createTable
(
m_dbConnection
.
get
()
)
)
==
false
)
Device
::
createTable
(
m_dbConnection
.
get
()
)
)
==
false
)
{
LOG_ERROR
(
"Failed to create database structure"
);
return
false
;
...
...
@@ -267,14 +267,14 @@ bool MediaLibrary::deleteFolder( FolderPtr folder )
return
true
;
}
std
::
shared_ptr
<
Mountpoint
>
MediaLibrary
::
mountpoint
(
const
std
::
string
&
uuid
)
std
::
shared_ptr
<
Device
>
MediaLibrary
::
device
(
const
std
::
string
&
uuid
)
{
return
Mountpoint
::
fromUuid
(
m_dbConnection
.
get
(),
uuid
);
return
Device
::
fromUuid
(
m_dbConnection
.
get
(),
uuid
);
}
std
::
shared_ptr
<
Mountpoint
>
MediaLibrary
::
add
Mountpoint
(
const
std
::
string
&
uuid
,
bool
isRemovable
)
std
::
shared_ptr
<
Device
>
MediaLibrary
::
add
Device
(
const
std
::
string
&
uuid
,
bool
isRemovable
)
{
return
Mountpoint
::
create
(
m_dbConnection
.
get
(),
uuid
,
isRemovable
);
return
Device
::
create
(
m_dbConnection
.
get
(),
uuid
,
isRemovable
);
}
LabelPtr
MediaLibrary
::
createLabel
(
const
std
::
string
&
label
)
...
...
src/MediaLibrary.h
View file @
e5b274e8
...
...
@@ -38,7 +38,7 @@ class Artist;
class
Media
;
class
Movie
;
class
Show
;
class
Mountpoint
;
class
Device
;
class
MediaLibrary
:
public
IMediaLibrary
{
...
...
@@ -58,8 +58,8 @@ class MediaLibrary : public IMediaLibrary
virtual
FolderPtr
folder
(
const
std
::
string
&
path
)
override
;
bool
deleteFolder
(
FolderPtr
folder
);
std
::
shared_ptr
<
Mountpoint
>
mountpoint
(
const
std
::
string
&
uuid
);
std
::
shared_ptr
<
Mountpoint
>
addMountpoint
(
const
std
::
string
&
uuid
,
bool
isRemovable
);
std
::
shared_ptr
<
Device
>
device
(
const
std
::
string
&
uuid
);
std
::
shared_ptr
<
Device
>
addDevice
(
const
std
::
string
&
uuid
,
bool
isRemovable
);
virtual
LabelPtr
createLabel
(
const
std
::
string
&
label
)
override
;
virtual
bool
deleteLabel
(
LabelPtr
label
)
override
;
...
...
src/discoverer/FsDiscoverer.cpp
View file @
e5b274e8
...
...
@@ -26,9 +26,9 @@
#include
<queue>
#include
"factory/FileSystem.h"
#include
"filesystem/I
Mountpoint
.h"
#include
"filesystem/I
Device
.h"
#include
"Media.h"
#include
"
Mountpoint
.h"
#include
"
Device
.h"
#include
"Folder.h"
#include
"logging/Logger.h"
#include
"MediaLibrary.h"
...
...
@@ -74,14 +74,14 @@ bool FsDiscoverer::discover( const std::string &entryPoint )
auto
f
=
Folder
::
create
(
m_dbConn
,
fsDir
->
path
(),
0
,
fsDir
->
isRemovable
(),
0
);
if
(
f
==
nullptr
)
return
false
;
// Since this is the "root" folder, we will always try to add
its mountpoint to our mountpoint list.
// We can then check if the subfolders
mountpoint
are different
auto
mountpoint
Fs
=
fsDir
->
mountpoint
();
auto
mountpoint
=
Mountpoint
::
fromUuid
(
m_dbConn
,
mountpoint
Fs
->
uuid
()
);
if
(
mountpoint
==
nullptr
)
// Since this is the "root" folder, we will always try to add
the device it's located on
//
to our devices list.
We can then check if the subfolders
containing device
are different
auto
device
Fs
=
fsDir
->
device
();
auto
device
=
Device
::
fromUuid
(
m_dbConn
,
device
Fs
->
uuid
()
);
if
(
device
==
nullptr
)
{
LOG_INFO
(
"Creating new
mountpoint "
,
mountpoint
Fs
->
uuid
()
);
mountpoint
=
Mountpoint
::
create
(
m_dbConn
,
mountpoint
Fs
->
uuid
(),
mountpoint
Fs
->
isRemovable
()
);
LOG_INFO
(
"Creating new
device in DB "
,
device
Fs
->
uuid
()
);
device
=
Device
::
create
(
m_dbConn
,
device
Fs
->
uuid
(),
device
Fs
->
isRemovable
()
);
}
checkFiles
(
fsDir
.
get
(),
f
);
checkSubfolders
(
fsDir
.
get
(),
f
,
blist
);
...
...
src/filesystem/unix/
Mountpoint
.cpp
→
src/filesystem/unix/
Device
.cpp
View file @
e5b274e8
...
...
@@ -20,7 +20,7 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include
"
Mountpoint
.h"
#include
"
Device
.h"
#include
<mntent.h>
#include
<cstring>
...
...
@@ -28,52 +28,51 @@
namespace
{
// Allow private ctors to be used from make_shared
struct
Mountpoint
Builder
:
fs
::
Mountpoint
struct
Device
Builder
:
fs
::
Device
{
Mountpoint
Builder
(
const
std
::
string
&
path
)
:
Mountpoint
(
path
)
{}
Device
Builder
(
const
std
::
string
&
path
)
:
Device
(
path
)
{}
};
}
namespace
fs
{
const
Mountpoint
::
MountpointMap
Mountpoint
::
Cache
=
Mountpoint
::
listMountpoints
();
std
::
shared_ptr
<
IMountpoint
>
Mountpoint
::
unknownMountpoint
=
std
::
make_shared
<
UnknownMountpoint
>
();
const
Device
::
DeviceMap
Device
::
Cache
=
Device
::
listDevices
();
Mountpoint
::
Mountpoint
(
const
std
::
string
&
devicePath
)
Device
::
Device
(
const
std
::
string
&
devicePath
)
:
m_device
(
devicePath
)
,
m_uuid
(
"fake uuid"
)
{
}
const
std
::
string
&
Mountpoint
::
uuid
()
const
const
std
::
string
&
Device
::
uuid
()
const
{
return
m_uuid
;
}
bool
Mountpoint
::
isPresent
()
const
bool
Device
::
isPresent
()
const
{
return
true
;
}
bool
Mountpoint
::
isRemovable
()
const
bool
Device
::
isRemovable
()
const
{
return
false
;
}
std
::
shared_ptr
<
I
Mountpoint
>
Mountpoint
::
fromPath
(
const
std
::
string
&
path
)
std
::
shared_ptr
<
I
Device
>
Device
::
fromPath
(
const
std
::
string
&
path
)
{
for
(
const
auto
&
p
:
Cache
)
{
if
(
path
.
find
(
p
.
first
)
==
0
)
return
p
.
second
;
}
return
unknownMountpoint
;
return
nullptr
;
}
Mountpoint
::
MountpointMap
Mountpoint
::
listMountpoint
s
()
Device
::
DeviceMap
Device
::
listDevice
s
()
{
Mountpoint
Map
res
;
Device
Map
res
;
FILE
*
f
=
setmntent
(
"/etc/mtab"
,
"r"
);
if
(
f
==
nullptr
)
throw
std
::
runtime_error
(
"Failed to read /etc/mtab"
);
...
...
@@ -98,7 +97,7 @@ Mountpoint::MountpointMap Mountpoint::listMountpoints()
||
strcmp
(
s
.
mnt_type
,
"binfmt_misc"
)
==
0
||
strcmp
(
s
.
mnt_type
,
"tmpfs"
)
==
0
)
continue
;
res
[
s
.
mnt_dir
]
=
std
::
make_shared
<
Mountpoint
Builder
>
(
s
.
mnt_fsname
);
res
[
s
.
mnt_dir
]
=
std
::
make_shared
<
Device
Builder
>
(
s
.
mnt_fsname
);
}
return
res
;
}
...
...
src/filesystem/unix/
Mountpoint
.h
→
src/filesystem/unix/
Device
.h
View file @
e5b274e8
...
...
@@ -22,45 +22,33 @@
#pragma once
#include
"filesystem/I
Mountpoint
.h"
#include
"filesystem/I
Device
.h"
#include
<memory>
#include
<unordered_map>
namespace
fs
{
class
UnknownMountpoint
:
public
I
Mountpoint
class
Device
:
public
I
Device
{
public:
UnknownMountpoint
()
:
m_uuid
(
"unknown"
)
{}
virtual
const
std
::
string
&
uuid
()
const
override
{
return
m_uuid
;
}
virtual
bool
isPresent
()
const
override
{
return
true
;
}
virtual
bool
isRemovable
()
const
override
{
return
false
;
}
private:
std
::
string
m_uuid
;
};
class
Mountpoint
:
public
IMountpoint
{
public:
using
MountpointMap
=
std
::
unordered_map
<
std
::
string
,
std
::
shared_ptr
<
IMountpoint
>>
;
using
DeviceMap
=
std
::
unordered_map
<
std
::
string
,
std
::
shared_ptr
<
IDevice
>>
;
virtual
const
std
::
string
&
uuid
()
const
override
;
virtual
bool
isPresent
()
const
override
;
virtual
bool
isRemovable
()
const
override
;
static
std
::
shared_ptr
<
I
Mountpoint
>
fromPath
(
const
std
::
string
&
path
);
static
std
::
shared_ptr
<
I
Device
>
fromPath
(
const
std
::
string
&
path
);
protected:
Mountpoint
(
const
std
::
string
&
devicePath
);
Device
(
const
std
::
string
&
devicePath
);
private:
static
MountpointMap
listMountpoints
();
static
std
::
shared_ptr
<
IMountpoint
>
unknownMountpoint
;
static
DeviceMap
listDevices
();
private:
static
const
Mountpoint
Map
Cache
;
static
const
Device
Map
Cache
;
private:
std
::
string
m_device
;
...
...
src/filesystem/unix/Directory.cpp
View file @
e5b274e8
...
...
@@ -22,7 +22,7 @@
#include
"Directory.h"
#include
"Media.h"
#include
"
Mountpoint
.h"
#include
"
Device
.h"
#include
<cstring>
#include
<cstdlib>
...
...
@@ -72,10 +72,10 @@ unsigned int Directory::lastModificationDate() const
return
m_lastModificationDate
;
}
std
::
shared_ptr
<
I
Mountpoint
>
Directory
::
mountpoint
()
const
std
::
shared_ptr
<
I
Device
>
Directory
::
device
()
const
{
//FIXME: Cache this?
return
Mountpoint
::
fromPath
(
m_path
);
return
Device
::
fromPath
(
m_path
);
}
bool
Directory
::
isRemovable
()
const
...
...
src/filesystem/unix/Directory.h
View file @
e5b274e8
...
...
@@ -36,7 +36,7 @@ public:
virtual
const
std
::
vector
<
std
::
string
>&
files
()
override
;
virtual
const
std
::
vector
<
std
::
string
>&
dirs
()
override
;
virtual
unsigned
int
lastModificationDate
()
const
override
;
virtual
std
::
shared_ptr
<
I
Mountpoint
>
mountpoint
()
const
override
;
virtual
std
::
shared_ptr
<
I
Device
>
device
()
const
override
;
virtual
bool
isRemovable
()
const
override
;
private:
...
...
test/mocks/FileSystem.h
View file @
e5b274e8
...
...
@@ -28,7 +28,7 @@
#include
"filesystem/IDirectory.h"
#include
"filesystem/IFile.h"
#include
"filesystem/I
Mountpoint
.h"
#include
"filesystem/I
Device
.h"
#include
"factory/IFileSystem.h"
#include
"utils/Filename.h"
...
...
@@ -86,10 +86,10 @@ public:
unsigned
int
m_lastModification
;
};
class
Mountpoint
:
public
fs
::
I
Mountpoint
class
Device
:
public
fs
::
I
Device
{
public:
Mountpoint
(
const
std
::
string
&
uuid
)
:
m_uuid
(
uuid
),
m_present
(
true
),
m_removable
(
false
)
{}
Device
(
const
std
::
string
&
uuid
)
:
m_uuid
(
uuid
),
m_present
(
true
),
m_removable
(
false
)
{}
virtual
const
std
::
string
&
uuid
()
const
override
{
return
m_uuid
;
}
virtual
bool
isPresent
()
const
override
{
return
m_present
;
}
virtual
bool
isRemovable
()
const
override
{
return
m_removable
;
}
...
...
@@ -106,12 +106,12 @@ private:
class
Directory
:
public
fs
::
IDirectory
{
public:
Directory
(
std
::
shared_ptr
<
mock
::
Directory
>
parent
,
const
std
::
string
&
path
,
unsigned
int
lastModif
,
std
::
shared_ptr
<
fs
::
I
Mountpoint
>
mountpoint
)
Directory
(
std
::
shared_ptr
<
mock
::
Directory
>
parent
,
const
std
::
string
&
path
,
unsigned
int
lastModif
,
std
::
shared_ptr
<
fs
::
I
Device
>
device
)
:
m_path
(
path
)
,
m_parent
(
parent
)
,
m_lastModificationDate
(
lastModif
)
,
m_isRemovable
(
false
)
,
m_
mountpoint
(
mountpoint
)
,
m_
device
(
device
)
{
}
...
...
@@ -135,9 +135,9 @@ public:
return
m_lastModificationDate
;
}
virtual
std
::
shared_ptr
<
fs
::
I
Mountpoint
>
mountpoint
()
const
override
virtual
std
::
shared_ptr
<
fs
::
I
Device
>
device
()
const
override
{
return
m_
mountpoint
;
return
m_
device
;
}
void
addFile
(
const
std
::
string
&
fileName
)
...
...
@@ -201,7 +201,7 @@ private:
std
::
shared_ptr
<
mock
::
Directory
>
m_parent
;
unsigned
int
m_lastModificationDate
;
bool
m_isRemovable
;
std
::
shared_ptr
<
fs
::
I
Mountpoint
>
m_mountpoint
;
std
::
shared_ptr
<
fs
::
I
Device
>
m_device
;
};
...
...
@@ -212,16 +212,16 @@ struct FileSystemFactory : public factory::IFileSystem
FileSystemFactory
()
{
auto
root
Mountpoint
=
std
::
make_shared
<
Mountpoint
>
(
"root"
);
auto
removable
Mountpoint
=
std
::
make_shared
<
Mountpoint
>
(
"removable"
);
removable
Mountpoint
->
setRemovable
(
true
);
removable
Mountpoint
->
setPresent
(
true
);
dirs
[
Root
]
=
std
::
unique_ptr
<
mock
::
Directory
>
(
new
Directory
{
nullptr
,
Root
,
123
,
root
Mountpoint
}
);
auto
root
Device
=
std
::
make_shared
<
Device
>
(
"root"
);
auto
removable
Device
=
std
::
make_shared
<
Device
>
(
"removable"
);
removable
Device
->
setRemovable
(
true
);
removable
Device
->
setPresent
(
true
);
dirs
[
Root
]
=
std
::
unique_ptr
<
mock
::
Directory
>
(
new
Directory
{
nullptr
,
Root
,
123
,
root
Device
}
);
addFile
(
Root
,
"video.avi"
);
addFile
(
Root
,
"audio.mp3"
);
addFile
(
Root
,
"not_a_media.something"
);
addFile
(
Root
,
"some_other_file.seaotter"
);
addFolder
(
Root
,
"folder/"
,
456
,
removable
Mountpoint
);
addFolder
(
Root
,
"folder/"
,
456
,
removable
Device
);
addFile
(
SubFolder
,
"subfile.mp4"
);
}
...
...
@@ -231,11 +231,11 @@ struct FileSystemFactory : public factory::IFileSystem
files
[
path
+
fileName
]
=
std
::
unique_ptr
<
mock
::
File
>
(
new
mock
::
File
(
path
+
fileName
)
);
}
void
addFolder
(
const
std
::
string
&
parentPath
,
const
std
::
string
&
path
,
unsigned
int
lastModif
,
std
::
shared_ptr
<
fs
::
I
Mountpoint
>
mountpoint
)
void
addFolder
(
const
std
::
string
&
parentPath
,
const
std
::
string
&
path
,
unsigned
int
lastModif
,
std
::
shared_ptr
<
fs
::
I
Device
>
device
)
{
auto
parent
=
dirs
[
parentPath
];
parent
->
addFolder
(
path
);
dirs
[
parentPath
+
path
]
=
std
::
unique_ptr
<
mock
::
Directory
>
(
new
Directory
(
parent
,
parentPath
+
path
,
lastModif
,
mountpoint
)
);
dirs
[
parentPath
+
path
]
=
std
::
unique_ptr
<
mock
::
Directory
>
(
new
Directory
(
parent
,
parentPath
+
path
,
lastModif
,
device
)
);
}
void
removeFile
(
const
std
::
string
&
path
,
const
std
::
string
&
fileName
)
...
...
test/unittest/
Mountpoint
Tests.cpp
→
test/unittest/
Device
Tests.cpp
View file @
e5b274e8
...
...
@@ -22,40 +22,40 @@
#include
"Tests.h"
#include
"
Mountpoint
.h"
#include
"
Device
.h"
class
Mountpoint
s
:
public
Tests
class
Device
s
:
public
Tests
{
};
TEST_F
(
Mountpoint
s
,
Create
)
TEST_F
(
Device
s
,
Create
)
{
auto
m
=
ml
->
add
Mountpoint
(
"dummy"
,
true
);
ASSERT_NE
(
nullptr
,
m
);
ASSERT_EQ
(
"dummy"
,
m
->
uuid
()
);
ASSERT_TRUE
(
m
->
isRemovable
()
);
ASSERT_TRUE
(
m
->
isPresent
()
);
auto
d
=
ml
->
add
Device
(
"dummy"
,
true
);
ASSERT_NE
(
nullptr
,
d
);
ASSERT_EQ
(
"dummy"
,
d
->
uuid
()
);
ASSERT_TRUE
(
d
->
isRemovable
()
);
ASSERT_TRUE
(
d
->
isPresent
()
);
Reload
();
m
=
ml
->
mountpoint
(
"dummy"
);
ASSERT_NE
(
nullptr
,
m
);
ASSERT_EQ
(
"dummy"
,
m
->
uuid
()
);
ASSERT_TRUE
(
m
->
isRemovable
()