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
fbf887d5
Commit
fbf887d5
authored
Jan 28, 2016
by
Hugo Beauzée-Luyssen
Browse files
MediaLibrary: addFile: Expect a fs::IFile instead of a path
parent
8e9656c4
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/MediaLibrary.cpp
View file @
fbf887d5
...
...
@@ -201,21 +201,10 @@ std::vector<MediaPtr> MediaLibrary::videoFiles()
return
Media
::
fetchAll
<
IMedia
>
(
m_dbConnection
.
get
(),
req
,
IMedia
::
Type
::
VideoType
);
}
std
::
shared_ptr
<
Media
>
MediaLibrary
::
addFile
(
const
std
::
string
&
path
,
Folder
&
parentFolder
,
fs
::
IDirectory
&
parentFolderFs
)
std
::
shared_ptr
<
Media
>
MediaLibrary
::
addFile
(
const
fs
::
IFile
&
fileFs
,
Folder
&
parentFolder
,
fs
::
IDirectory
&
parentFolderFs
)
{
std
::
shared_ptr
<
fs
::
IFile
>
fileFs
;
try
{
fileFs
=
m_fsFactory
->
createFile
(
path
);
}
catch
(
std
::
exception
&
ex
)
{
LOG_ERROR
(
"Failed to create an IFile for "
,
path
,
": "
,
ex
.
what
()
);
return
nullptr
;
}
auto
type
=
IMedia
::
Type
::
UnknownType
;
auto
ext
=
fileFs
->
extension
();
auto
ext
=
fileFs
.
extension
();
auto
predicate
=
[
ext
](
const
std
::
string
&
v
)
{
return
strcasecmp
(
v
.
c_str
(),
ext
.
c_str
())
==
0
;
};
...
...
@@ -233,18 +222,18 @@ std::shared_ptr<Media> MediaLibrary::addFile( const std::string& path, Folder& p
if
(
type
==
IMedia
::
Type
::
UnknownType
)
return
nullptr
;
LOG_INFO
(
"Adding "
,
p
ath
);
auto
mptr
=
Media
::
create
(
m_dbConnection
.
get
(),
type
,
*
fileFs
);
LOG_INFO
(
"Adding "
,
fileFs
.
fullP
ath
()
);
auto
mptr
=
Media
::
create
(
m_dbConnection
.
get
(),
type
,
fileFs
);
if
(
mptr
==
nullptr
)
{
LOG_ERROR
(
"Failed to add media "
,
fileFs
->
fullPath
(),
" to the media library"
);
LOG_ERROR
(
"Failed to add media "
,
fileFs
.
fullPath
(),
" to the media library"
);
return
nullptr
;
}
// For now, assume all media are made of a single file
auto
file
=
mptr
->
addFile
(
*
fileFs
,
parentFolder
,
parentFolderFs
,
File
::
Type
::
Entire
);
auto
file
=
mptr
->
addFile
(
fileFs
,
parentFolder
,
parentFolderFs
,
File
::
Type
::
Entire
);
if
(
file
==
nullptr
)
{
LOG_ERROR
(
"Failed to add file "
,
fileFs
->
fullPath
(),
" to media #"
,
mptr
->
id
()
);
LOG_ERROR
(
"Failed to add file "
,
fileFs
.
fullPath
(),
" to media #"
,
mptr
->
id
()
);
Media
::
destroy
(
m_dbConnection
.
get
(),
mptr
->
id
()
);
return
nullptr
;
}
...
...
src/MediaLibrary.h
View file @
fbf887d5
...
...
@@ -59,7 +59,7 @@ class MediaLibrary : public IMediaLibrary
std
::
vector
<
MediaPtr
>
files
();
virtual
std
::
vector
<
MediaPtr
>
audioFiles
()
override
;
virtual
std
::
vector
<
MediaPtr
>
videoFiles
()
override
;
std
::
shared_ptr
<
Media
>
addFile
(
const
std
::
string
&
path
,
Folder
&
parentFolder
,
fs
::
IDirectory
&
parentFolderFs
);
std
::
shared_ptr
<
Media
>
addFile
(
const
fs
::
IFile
&
fileFs
,
Folder
&
parentFolder
,
fs
::
IDirectory
&
parentFolderFs
);
bool
deleteFolder
(
const
Folder
&
folder
);
std
::
shared_ptr
<
Device
>
device
(
const
std
::
string
&
uuid
);
...
...
src/discoverer/FsDiscoverer.cpp
View file @
fbf887d5
...
...
@@ -222,7 +222,7 @@ void FsDiscoverer::checkFiles( fs::IDirectory& parentFolderFs, Folder& parentFol
f
->
media
()
->
removeFile
(
*
f
);
// Insert all files at once to avoid SQL write contention
for
(
auto
&
p
:
filesToAdd
)
m_ml
->
addFile
(
p
->
fullPath
()
,
parentFolder
,
parentFolderFs
);
m_ml
->
addFile
(
*
p
,
parentFolder
,
parentFolderFs
);
t
->
commit
();
LOG_INFO
(
"Done checking files in "
,
parentFolderFs
.
path
()
);
}
...
...
test/unittest/Tests.cpp
View file @
fbf887d5
...
...
@@ -121,7 +121,8 @@ std::shared_ptr<Folder> MediaLibraryTester::folder( const std::string& path )
std
::
shared_ptr
<
Media
>
MediaLibraryTester
::
addFile
(
const
std
::
string
&
path
)
{
return
MediaLibrary
::
addFile
(
path
,
dummyFolder
,
*
dummyDirectory
);
mock
::
NoopFile
file
(
path
);
return
MediaLibrary
::
addFile
(
file
,
dummyFolder
,
*
dummyDirectory
);
}
std
::
shared_ptr
<
Playlist
>
MediaLibraryTester
::
playlist
(
unsigned
int
playlistId
)
...
...
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