Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
61eb2aa3
Commit
61eb2aa3
authored
Jan 21, 2018
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
storage/Interface: wrap StorageDirectoryReader in std::unique_ptr
parent
a9847ebf
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
29 additions
and
33 deletions
+29
-33
Walk.cxx
src/db/update/Walk.cxx
+1
-1
CompositeStorage.cxx
src/storage/CompositeStorage.cxx
+9
-14
CompositeStorage.hxx
src/storage/CompositeStorage.hxx
+1
-1
StorageInterface.hxx
src/storage/StorageInterface.hxx
+2
-1
CurlStorage.cxx
src/storage/plugins/CurlStorage.cxx
+5
-5
LocalStorage.cxx
src/storage/plugins/LocalStorage.cxx
+3
-3
NfsStorage.cxx
src/storage/plugins/NfsStorage.cxx
+4
-4
SmbclientStorage.cxx
src/storage/plugins/SmbclientStorage.cxx
+4
-3
run_storage.cxx
test/run_storage.cxx
+0
-1
No files found.
src/db/update/Walk.cxx
View file @
61eb2aa3
...
@@ -337,7 +337,7 @@ UpdateWalk::UpdateDirectory(Directory &directory,
...
@@ -337,7 +337,7 @@ UpdateWalk::UpdateDirectory(Directory &directory,
std
::
unique_ptr
<
StorageDirectoryReader
>
reader
;
std
::
unique_ptr
<
StorageDirectoryReader
>
reader
;
try
{
try
{
reader
.
reset
(
storage
.
OpenDirectory
(
directory
.
GetPath
()
));
reader
=
storage
.
OpenDirectory
(
directory
.
GetPath
(
));
}
catch
(...)
{
}
catch
(...)
{
LogError
(
std
::
current_exception
());
LogError
(
std
::
current_exception
());
return
false
;
return
false
;
...
...
src/storage/CompositeStorage.cxx
View file @
61eb2aa3
...
@@ -33,25 +33,20 @@
...
@@ -33,25 +33,20 @@
* instance and the virtual directory entries.
* instance and the virtual directory entries.
*/
*/
class
CompositeDirectoryReader
final
:
public
StorageDirectoryReader
{
class
CompositeDirectoryReader
final
:
public
StorageDirectoryReader
{
StorageDirectoryReader
*
other
;
std
::
unique_ptr
<
StorageDirectoryReader
>
other
;
std
::
set
<
std
::
string
>
names
;
std
::
set
<
std
::
string
>
names
;
std
::
set
<
std
::
string
>::
const_iterator
current
,
next
;
std
::
set
<
std
::
string
>::
const_iterator
current
,
next
;
public
:
public
:
template
<
typename
M
>
template
<
typename
O
,
typename
M
>
CompositeDirectoryReader
(
StorageDirectoryReader
*
_other
,
CompositeDirectoryReader
(
O
&&
_other
,
const
M
&
map
)
const
M
&
map
)
:
other
(
std
::
forward
<
O
>
(
_other
))
{
:
other
(
_other
)
{
for
(
const
auto
&
i
:
map
)
for
(
const
auto
&
i
:
map
)
names
.
insert
(
i
.
first
);
names
.
insert
(
i
.
first
);
next
=
names
.
begin
();
next
=
names
.
begin
();
}
}
virtual
~
CompositeDirectoryReader
()
{
delete
other
;
}
/* virtual methods from class StorageDirectoryReader */
/* virtual methods from class StorageDirectoryReader */
const
char
*
Read
()
noexcept
override
;
const
char
*
Read
()
noexcept
override
;
StorageFileInfo
GetInfo
(
bool
follow
)
override
;
StorageFileInfo
GetInfo
(
bool
follow
)
override
;
...
@@ -67,8 +62,7 @@ CompositeDirectoryReader::Read() noexcept
...
@@ -67,8 +62,7 @@ CompositeDirectoryReader::Read() noexcept
return
name
;
return
name
;
}
}
delete
other
;
other
.
reset
();
other
=
nullptr
;
}
}
if
(
next
==
names
.
end
())
if
(
next
==
names
.
end
())
...
@@ -271,7 +265,7 @@ CompositeStorage::GetInfo(const char *uri, bool follow)
...
@@ -271,7 +265,7 @@ CompositeStorage::GetInfo(const char *uri, bool follow)
throw
std
::
runtime_error
(
"No such file or directory"
);
throw
std
::
runtime_error
(
"No such file or directory"
);
}
}
StorageDirectoryReader
*
std
::
unique_ptr
<
StorageDirectoryReader
>
CompositeStorage
::
OpenDirectory
(
const
char
*
uri
)
CompositeStorage
::
OpenDirectory
(
const
char
*
uri
)
{
{
const
std
::
lock_guard
<
Mutex
>
protect
(
mutex
);
const
std
::
lock_guard
<
Mutex
>
protect
(
mutex
);
...
@@ -287,14 +281,15 @@ CompositeStorage::OpenDirectory(const char *uri)
...
@@ -287,14 +281,15 @@ CompositeStorage::OpenDirectory(const char *uri)
return
f
.
directory
->
storage
->
OpenDirectory
(
f
.
uri
);
return
f
.
directory
->
storage
->
OpenDirectory
(
f
.
uri
);
}
}
StorageDirectoryReader
*
other
=
nullpt
r
;
std
::
unique_ptr
<
StorageDirectoryReader
>
othe
r
;
try
{
try
{
other
=
f
.
directory
->
storage
->
OpenDirectory
(
f
.
uri
);
other
=
f
.
directory
->
storage
->
OpenDirectory
(
f
.
uri
);
}
catch
(...)
{
}
catch
(...)
{
}
}
return
new
CompositeDirectoryReader
(
other
,
directory
->
children
);
return
std
::
make_unique
<
CompositeDirectoryReader
>
(
std
::
move
(
other
),
directory
->
children
);
}
}
std
::
string
std
::
string
...
...
src/storage/CompositeStorage.hxx
View file @
61eb2aa3
...
@@ -119,7 +119,7 @@ public:
...
@@ -119,7 +119,7 @@ public:
/* virtual methods from class Storage */
/* virtual methods from class Storage */
StorageFileInfo
GetInfo
(
const
char
*
uri
,
bool
follow
)
override
;
StorageFileInfo
GetInfo
(
const
char
*
uri
,
bool
follow
)
override
;
StorageDirectoryReader
*
OpenDirectory
(
const
char
*
uri
)
override
;
std
::
unique_ptr
<
StorageDirectoryReader
>
OpenDirectory
(
const
char
*
uri
)
override
;
std
::
string
MapUTF8
(
const
char
*
uri
)
const
noexcept
override
;
std
::
string
MapUTF8
(
const
char
*
uri
)
const
noexcept
override
;
...
...
src/storage/StorageInterface.hxx
View file @
61eb2aa3
...
@@ -23,6 +23,7 @@
...
@@ -23,6 +23,7 @@
#include "check.h"
#include "check.h"
#include "Compiler.h"
#include "Compiler.h"
#include <memory>
#include <string>
#include <string>
struct
StorageFileInfo
;
struct
StorageFileInfo
;
...
@@ -56,7 +57,7 @@ public:
...
@@ -56,7 +57,7 @@ public:
/**
/**
* Throws #std::runtime_error on error.
* Throws #std::runtime_error on error.
*/
*/
virtual
StorageDirectoryReader
*
OpenDirectory
(
const
char
*
uri_utf8
)
=
0
;
virtual
std
::
unique_ptr
<
StorageDirectoryReader
>
OpenDirectory
(
const
char
*
uri_utf8
)
=
0
;
/**
/**
* Map the given relative URI to an absolute URI.
* Map the given relative URI to an absolute URI.
...
...
src/storage/plugins/CurlStorage.cxx
View file @
61eb2aa3
...
@@ -60,7 +60,7 @@ public:
...
@@ -60,7 +60,7 @@ public:
/* virtual methods from class Storage */
/* virtual methods from class Storage */
StorageFileInfo
GetInfo
(
const
char
*
uri_utf8
,
bool
follow
)
override
;
StorageFileInfo
GetInfo
(
const
char
*
uri_utf8
,
bool
follow
)
override
;
StorageDirectoryReader
*
OpenDirectory
(
const
char
*
uri_utf8
)
override
;
std
::
unique_ptr
<
StorageDirectoryReader
>
OpenDirectory
(
const
char
*
uri_utf8
)
override
;
std
::
string
MapUTF8
(
const
char
*
uri_utf8
)
const
noexcept
override
;
std
::
string
MapUTF8
(
const
char
*
uri_utf8
)
const
noexcept
override
;
...
@@ -474,14 +474,14 @@ public:
...
@@ -474,14 +474,14 @@ public:
:
PropfindOperation
(
curl
,
uri
,
1
),
:
PropfindOperation
(
curl
,
uri
,
1
),
base_path
(
UriPathOrSlash
(
uri
))
{}
base_path
(
UriPathOrSlash
(
uri
))
{}
StorageDirectoryReader
*
Perform
()
{
std
::
unique_ptr
<
StorageDirectoryReader
>
Perform
()
{
Wait
();
Wait
();
return
ToReader
();
return
ToReader
();
}
}
private
:
private
:
StorageDirectoryReader
*
ToReader
()
{
std
::
unique_ptr
<
StorageDirectoryReader
>
ToReader
()
{
return
new
MemoryStorageDirectoryReader
(
std
::
move
(
entries
));
return
std
::
make_unique
<
MemoryStorageDirectoryReader
>
(
std
::
move
(
entries
));
}
}
/**
/**
...
@@ -534,7 +534,7 @@ protected:
...
@@ -534,7 +534,7 @@ protected:
}
}
};
};
StorageDirectoryReader
*
std
::
unique_ptr
<
StorageDirectoryReader
>
CurlStorage
::
OpenDirectory
(
const
char
*
uri_utf8
)
CurlStorage
::
OpenDirectory
(
const
char
*
uri_utf8
)
{
{
// TODO: escape the given URI
// TODO: escape the given URI
...
...
src/storage/plugins/LocalStorage.cxx
View file @
61eb2aa3
...
@@ -59,7 +59,7 @@ public:
...
@@ -59,7 +59,7 @@ public:
/* virtual methods from class Storage */
/* virtual methods from class Storage */
StorageFileInfo
GetInfo
(
const
char
*
uri_utf8
,
bool
follow
)
override
;
StorageFileInfo
GetInfo
(
const
char
*
uri_utf8
,
bool
follow
)
override
;
StorageDirectoryReader
*
OpenDirectory
(
const
char
*
uri_utf8
)
override
;
std
::
unique_ptr
<
StorageDirectoryReader
>
OpenDirectory
(
const
char
*
uri_utf8
)
override
;
std
::
string
MapUTF8
(
const
char
*
uri_utf8
)
const
noexcept
override
;
std
::
string
MapUTF8
(
const
char
*
uri_utf8
)
const
noexcept
override
;
...
@@ -140,10 +140,10 @@ LocalStorage::GetInfo(const char *uri_utf8, bool follow)
...
@@ -140,10 +140,10 @@ LocalStorage::GetInfo(const char *uri_utf8, bool follow)
return
Stat
(
MapFSOrThrow
(
uri_utf8
),
follow
);
return
Stat
(
MapFSOrThrow
(
uri_utf8
),
follow
);
}
}
StorageDirectoryReader
*
std
::
unique_ptr
<
StorageDirectoryReader
>
LocalStorage
::
OpenDirectory
(
const
char
*
uri_utf8
)
LocalStorage
::
OpenDirectory
(
const
char
*
uri_utf8
)
{
{
return
new
LocalDirectoryReader
(
MapFSOrThrow
(
uri_utf8
));
return
std
::
make_unique
<
LocalDirectoryReader
>
(
MapFSOrThrow
(
uri_utf8
));
}
}
gcc_pure
gcc_pure
...
...
src/storage/plugins/NfsStorage.cxx
View file @
61eb2aa3
...
@@ -88,7 +88,7 @@ public:
...
@@ -88,7 +88,7 @@ public:
/* virtual methods from class Storage */
/* virtual methods from class Storage */
StorageFileInfo
GetInfo
(
const
char
*
uri_utf8
,
bool
follow
)
override
;
StorageFileInfo
GetInfo
(
const
char
*
uri_utf8
,
bool
follow
)
override
;
StorageDirectoryReader
*
OpenDirectory
(
const
char
*
uri_utf8
)
override
;
std
::
unique_ptr
<
StorageDirectoryReader
>
OpenDirectory
(
const
char
*
uri_utf8
)
override
;
std
::
string
MapUTF8
(
const
char
*
uri_utf8
)
const
noexcept
override
;
std
::
string
MapUTF8
(
const
char
*
uri_utf8
)
const
noexcept
override
;
...
@@ -334,8 +334,8 @@ public:
...
@@ -334,8 +334,8 @@ public:
const
char
*
_path
)
const
char
*
_path
)
:
BlockingNfsOperation
(
_connection
),
path
(
_path
)
{}
:
BlockingNfsOperation
(
_connection
),
path
(
_path
)
{}
StorageDirectoryReader
*
ToReader
()
{
std
::
unique_ptr
<
StorageDirectoryReader
>
ToReader
()
{
return
new
MemoryStorageDirectoryReader
(
std
::
move
(
entries
));
return
std
::
make_unique
<
MemoryStorageDirectoryReader
>
(
std
::
move
(
entries
));
}
}
protected
:
protected
:
...
@@ -377,7 +377,7 @@ NfsListDirectoryOperation::CollectEntries(struct nfsdir *dir)
...
@@ -377,7 +377,7 @@ NfsListDirectoryOperation::CollectEntries(struct nfsdir *dir)
}
}
}
}
StorageDirectoryReader
*
std
::
unique_ptr
<
StorageDirectoryReader
>
NfsStorage
::
OpenDirectory
(
const
char
*
uri_utf8
)
NfsStorage
::
OpenDirectory
(
const
char
*
uri_utf8
)
{
{
const
std
::
string
path
=
UriToNfsPath
(
uri_utf8
);
const
std
::
string
path
=
UriToNfsPath
(
uri_utf8
);
...
...
src/storage/plugins/SmbclientStorage.cxx
View file @
61eb2aa3
...
@@ -67,7 +67,7 @@ public:
...
@@ -67,7 +67,7 @@ public:
/* virtual methods from class Storage */
/* virtual methods from class Storage */
StorageFileInfo
GetInfo
(
const
char
*
uri_utf8
,
bool
follow
)
override
;
StorageFileInfo
GetInfo
(
const
char
*
uri_utf8
,
bool
follow
)
override
;
StorageDirectoryReader
*
OpenDirectory
(
const
char
*
uri_utf8
)
override
;
std
::
unique_ptr
<
StorageDirectoryReader
>
OpenDirectory
(
const
char
*
uri_utf8
)
override
;
std
::
string
MapUTF8
(
const
char
*
uri_utf8
)
const
noexcept
override
;
std
::
string
MapUTF8
(
const
char
*
uri_utf8
)
const
noexcept
override
;
...
@@ -124,7 +124,7 @@ SmbclientStorage::GetInfo(const char *uri_utf8, gcc_unused bool follow)
...
@@ -124,7 +124,7 @@ SmbclientStorage::GetInfo(const char *uri_utf8, gcc_unused bool follow)
return
::
GetInfo
(
mapped
.
c_str
());
return
::
GetInfo
(
mapped
.
c_str
());
}
}
StorageDirectoryReader
*
std
::
unique_ptr
<
StorageDirectoryReader
>
SmbclientStorage
::
OpenDirectory
(
const
char
*
uri_utf8
)
SmbclientStorage
::
OpenDirectory
(
const
char
*
uri_utf8
)
{
{
std
::
string
mapped
=
MapUTF8
(
uri_utf8
);
std
::
string
mapped
=
MapUTF8
(
uri_utf8
);
...
@@ -138,7 +138,8 @@ SmbclientStorage::OpenDirectory(const char *uri_utf8)
...
@@ -138,7 +138,8 @@ SmbclientStorage::OpenDirectory(const char *uri_utf8)
throw
MakeErrno
(
"Failed to open directory"
);
throw
MakeErrno
(
"Failed to open directory"
);
}
}
return
new
SmbclientDirectoryReader
(
std
::
move
(
mapped
.
c_str
()),
handle
);
return
std
::
make_unique
<
SmbclientDirectoryReader
>
(
std
::
move
(
mapped
.
c_str
()),
handle
);
}
}
gcc_pure
gcc_pure
...
...
test/run_storage.cxx
View file @
61eb2aa3
...
@@ -82,7 +82,6 @@ Ls(Storage &storage, const char *path)
...
@@ -82,7 +82,6 @@ Ls(Storage &storage, const char *path)
mtime
,
name
);
mtime
,
name
);
}
}
delete
dir
;
return
EXIT_SUCCESS
;
return
EXIT_SUCCESS
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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