fs/Traits: add IsSpecialFilename()
Merge some duplicate code in a central library.
This commit is contained in:
parent
5faf76051d
commit
b7ce452308
@ -24,6 +24,7 @@
|
|||||||
#include "storage/StorageInterface.hxx"
|
#include "storage/StorageInterface.hxx"
|
||||||
#include "fs/AllocatedPath.hxx"
|
#include "fs/AllocatedPath.hxx"
|
||||||
#include "fs/FileInfo.hxx"
|
#include "fs/FileInfo.hxx"
|
||||||
|
#include "fs/Traits.hxx"
|
||||||
#include "Log.hxx"
|
#include "Log.hxx"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
@ -146,8 +147,7 @@ WatchDirectory::GetUriFS() const noexcept
|
|||||||
/* we don't look at "." / ".." nor files with newlines in their name */
|
/* we don't look at "." / ".." nor files with newlines in their name */
|
||||||
static bool skip_path(const char *path)
|
static bool skip_path(const char *path)
|
||||||
{
|
{
|
||||||
return (path[0] == '.' && path[1] == 0) ||
|
return PathTraitsFS::IsSpecialFilename(path) ||
|
||||||
(path[0] == '.' && path[1] == '.' && path[2] == 0) ||
|
|
||||||
strchr(path, '\n') != nullptr;
|
strchr(path, '\n') != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -237,7 +237,7 @@ try {
|
|||||||
LogError(std::current_exception());
|
LogError(std::current_exception());
|
||||||
}
|
}
|
||||||
|
|
||||||
/* we don't look at "." / ".." nor files with newlines in their name */
|
/* we don't look at files with newlines in their name */
|
||||||
gcc_pure
|
gcc_pure
|
||||||
static bool
|
static bool
|
||||||
skip_path(const char *name_utf8) noexcept
|
skip_path(const char *name_utf8) noexcept
|
||||||
|
@ -108,6 +108,12 @@ struct PathTraitsFS {
|
|||||||
return IsSeparator(*p);
|
return IsSeparator(*p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gcc_pure gcc_nonnull_all
|
||||||
|
static bool IsSpecialFilename(const_pointer_type name) noexcept {
|
||||||
|
return (name[0] == '.' && name[1] == 0) ||
|
||||||
|
(name[0] == '.' && name[1] == '.' && name[2] == 0);
|
||||||
|
}
|
||||||
|
|
||||||
gcc_pure gcc_nonnull_all
|
gcc_pure gcc_nonnull_all
|
||||||
static size_t GetLength(const_pointer_type p) noexcept {
|
static size_t GetLength(const_pointer_type p) noexcept {
|
||||||
return StringLength(p);
|
return StringLength(p);
|
||||||
@ -216,6 +222,12 @@ struct PathTraitsUTF8 {
|
|||||||
return IsSeparator(*p);
|
return IsSeparator(*p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gcc_pure gcc_nonnull_all
|
||||||
|
static bool IsSpecialFilename(const_pointer_type name) noexcept {
|
||||||
|
return (name[0] == '.' && name[1] == 0) ||
|
||||||
|
(name[0] == '.' && name[1] == '.' && name[2] == 0);
|
||||||
|
}
|
||||||
|
|
||||||
gcc_pure gcc_nonnull_all
|
gcc_pure gcc_nonnull_all
|
||||||
static size_t GetLength(const_pointer_type p) noexcept {
|
static size_t GetLength(const_pointer_type p) noexcept {
|
||||||
return StringLength(p);
|
return StringLength(p);
|
||||||
|
@ -144,21 +144,12 @@ LocalStorage::OpenDirectory(const char *uri_utf8)
|
|||||||
return std::make_unique<LocalDirectoryReader>(MapFSOrThrow(uri_utf8));
|
return std::make_unique<LocalDirectoryReader>(MapFSOrThrow(uri_utf8));
|
||||||
}
|
}
|
||||||
|
|
||||||
gcc_pure
|
|
||||||
static bool
|
|
||||||
SkipNameFS(PathTraitsFS::const_pointer_type name_fs) noexcept
|
|
||||||
{
|
|
||||||
return name_fs[0] == '.' &&
|
|
||||||
(name_fs[1] == 0 ||
|
|
||||||
(name_fs[1] == '.' && name_fs[2] == 0));
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
LocalDirectoryReader::Read() noexcept
|
LocalDirectoryReader::Read() noexcept
|
||||||
{
|
{
|
||||||
while (reader.ReadEntry()) {
|
while (reader.ReadEntry()) {
|
||||||
const Path name_fs = reader.GetEntry();
|
const Path name_fs = reader.GetEntry();
|
||||||
if (SkipNameFS(name_fs.c_str()))
|
if (PathTraitsFS::IsSpecialFilename(name_fs.c_str()))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
Loading…
Reference in New Issue
Block a user