diff --git a/src/db/update/InotifyUpdate.cxx b/src/db/update/InotifyUpdate.cxx index 374a1ea04..0885aa435 100644 --- a/src/db/update/InotifyUpdate.cxx +++ b/src/db/update/InotifyUpdate.cxx @@ -24,6 +24,7 @@ #include "storage/StorageInterface.hxx" #include "fs/AllocatedPath.hxx" #include "fs/FileInfo.hxx" +#include "fs/Traits.hxx" #include "Log.hxx" #include @@ -146,8 +147,7 @@ WatchDirectory::GetUriFS() const noexcept /* we don't look at "." / ".." nor files with newlines in their name */ static bool skip_path(const char *path) { - return (path[0] == '.' && path[1] == 0) || - (path[0] == '.' && path[1] == '.' && path[2] == 0) || + return PathTraitsFS::IsSpecialFilename(path) || strchr(path, '\n') != nullptr; } diff --git a/src/db/update/Walk.cxx b/src/db/update/Walk.cxx index e2c9b7a8c..eb853fcb8 100644 --- a/src/db/update/Walk.cxx +++ b/src/db/update/Walk.cxx @@ -237,7 +237,7 @@ try { 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 static bool skip_path(const char *name_utf8) noexcept diff --git a/src/fs/Traits.hxx b/src/fs/Traits.hxx index 6a7e31f0c..735ec6c9e 100644 --- a/src/fs/Traits.hxx +++ b/src/fs/Traits.hxx @@ -108,6 +108,12 @@ struct PathTraitsFS { 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 static size_t GetLength(const_pointer_type p) noexcept { return StringLength(p); @@ -216,6 +222,12 @@ struct PathTraitsUTF8 { 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 static size_t GetLength(const_pointer_type p) noexcept { return StringLength(p); diff --git a/src/storage/plugins/LocalStorage.cxx b/src/storage/plugins/LocalStorage.cxx index 562e0937a..662f8801e 100644 --- a/src/storage/plugins/LocalStorage.cxx +++ b/src/storage/plugins/LocalStorage.cxx @@ -144,21 +144,12 @@ LocalStorage::OpenDirectory(const char *uri_utf8) return std::make_unique(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 * LocalDirectoryReader::Read() noexcept { while (reader.ReadEntry()) { const Path name_fs = reader.GetEntry(); - if (SkipNameFS(name_fs.c_str())) + if (PathTraitsFS::IsSpecialFilename(name_fs.c_str())) continue; try {