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
ccac9c15
Commit
ccac9c15
authored
Nov 15, 2016
by
Hugo Beauzée-Luyssen
Browse files
IMediaLibrary: Add a removeEntryPoint method
Fix
#15
parent
6778d18d
Changes
6
Hide whitespace changes
Inline
Side-by-side
include/medialibrary/IMediaLibrary.h
View file @
ccac9c15
...
...
@@ -222,6 +222,7 @@ class IMediaLibrary
virtual
void
discover
(
const
std
::
string
&
entryPoint
)
=
0
;
virtual
void
setDiscoverNetworkEnabled
(
bool
enable
)
=
0
;
virtual
std
::
vector
<
FolderPtr
>
entryPoints
()
const
=
0
;
virtual
bool
removeEntryPoint
(
const
std
::
string
&
entryPoint
)
=
0
;
/**
* @brief banFolder will blacklist a folder for discovery
*/
...
...
src/Folder.cpp
View file @
ccac9c15
...
...
@@ -261,6 +261,11 @@ bool Folder::isPresent() const
return
m_isPresent
;
}
bool
Folder
::
isRootFolder
()
const
{
return
m_parent
==
0
;
}
std
::
vector
<
std
::
shared_ptr
<
Folder
>>
Folder
::
fetchRootFolders
(
MediaLibraryPtr
ml
)
{
static
const
std
::
string
req
=
"SELECT * FROM "
+
policy
::
FolderTable
::
Name
...
...
src/Folder.h
View file @
ccac9c15
...
...
@@ -75,6 +75,7 @@ public:
std
::
shared_ptr
<
Folder
>
parent
();
int64_t
deviceId
()
const
;
virtual
bool
isPresent
()
const
override
;
bool
isRootFolder
()
const
;
private:
enum
class
BannedType
...
...
src/MediaLibrary.cpp
View file @
ccac9c15
...
...
@@ -705,6 +705,30 @@ std::vector<FolderPtr> MediaLibrary::entryPoints() const
return
Folder
::
fetchAll
<
IFolder
>
(
this
,
req
);
}
bool
MediaLibrary
::
removeEntryPoint
(
const
std
::
string
&
entryPoint
)
{
auto
folder
=
Folder
::
fromPath
(
this
,
entryPoint
);
if
(
folder
==
nullptr
)
{
LOG_WARN
(
"Can't remove unknown entrypoint: "
,
entryPoint
);
return
false
;
}
// The easy case is that this folder was directly discovered. In which case, we just
// have to delete it and it won't be discovered again.
// If it isn't, we also have to ban it to prevent it from reappearing. The Folder::banFolder
// method already handles the prior deletion
bool
res
;
if
(
folder
->
isRootFolder
()
==
false
)
res
=
banFolder
(
entryPoint
);
else
res
=
deleteFolder
(
*
folder
);
if
(
res
==
false
)
return
false
;
// Force a cache cleanup to avoid stalled media
Media
::
clear
();
return
true
;
}
bool
MediaLibrary
::
banFolder
(
const
std
::
string
&
path
)
{
return
Folder
::
blacklist
(
this
,
path
);
...
...
src/MediaLibrary.h
View file @
ccac9c15
...
...
@@ -116,6 +116,7 @@ class MediaLibrary : public IMediaLibrary, public IDeviceListerCb
virtual
void
discover
(
const
std
::
string
&
entryPoint
)
override
;
virtual
void
setDiscoverNetworkEnabled
(
bool
enabled
)
override
;
virtual
std
::
vector
<
FolderPtr
>
entryPoints
()
const
override
;
virtual
bool
removeEntryPoint
(
const
std
::
string
&
entryPoint
)
override
;
virtual
bool
banFolder
(
const
std
::
string
&
path
)
override
;
virtual
bool
unbanFolder
(
const
std
::
string
&
path
)
override
;
...
...
test/unittest/FolderTests.cpp
View file @
ccac9c15
...
...
@@ -433,3 +433,48 @@ TEST_F( Folders, FetchEntryPoints )
eps
=
ml
->
entryPoints
();
ASSERT_EQ
(
1u
,
eps
.
size
()
);
}
TEST_F
(
Folders
,
RemoveRootEntryPoint
)
{
auto
media
=
ml
->
files
();
ASSERT_NE
(
0u
,
media
.
size
()
);
auto
res
=
ml
->
removeEntryPoint
(
mock
::
FileSystemFactory
::
Root
);
ASSERT_TRUE
(
res
);
media
=
ml
->
files
();
ASSERT_EQ
(
0u
,
media
.
size
()
);
auto
eps
=
ml
->
entryPoints
();
ASSERT_EQ
(
0u
,
eps
.
size
()
);
}
TEST_F
(
Folders
,
RemoveEntryPoint
)
{
auto
media
=
ml
->
files
();
ASSERT_NE
(
0u
,
media
.
size
()
);
auto
res
=
ml
->
removeEntryPoint
(
mock
::
FileSystemFactory
::
SubFolder
);
ASSERT_TRUE
(
res
);
media
=
ml
->
files
();
ASSERT_NE
(
0u
,
media
.
size
()
);
auto
eps
=
ml
->
entryPoints
();
ASSERT_EQ
(
1u
,
eps
.
size
()
);
cbMock
->
prepareForReload
();
ml
->
reload
();
auto
reloaded
=
cbMock
->
wait
();
ASSERT_TRUE
(
reloaded
);
// Ensure it wasn't re-discovered, ie. that it was properly blacklisted
auto
media2
=
ml
->
files
();
ASSERT_EQ
(
media
.
size
(),
media2
.
size
()
);
}
TEST_F
(
Folders
,
RemoveNonExistantEntryPoint
)
{
auto
res
=
ml
->
removeEntryPoint
(
"/sea/otter"
);
ASSERT_FALSE
(
res
);
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment