From 96e20826f358a32e38c3f052243375982543c05b Mon Sep 17 00:00:00 2001 From: Daniel Wilhelm Date: Fri, 2 Oct 2015 14:54:34 +0200 Subject: 6.14 --- zen/file_traverser.h | 75 +++++++++++++++++++--------------------------------- 1 file changed, 27 insertions(+), 48 deletions(-) (limited to 'zen/file_traverser.h') diff --git a/zen/file_traverser.h b/zen/file_traverser.h index 174503b5..9cba9e58 100644 --- a/zen/file_traverser.h +++ b/zen/file_traverser.h @@ -4,64 +4,43 @@ // * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved * // ************************************************************************** -#ifndef FILETRAVERSER_H_INCLUDED -#define FILETRAVERSER_H_INCLUDED +#ifndef FOLDER_TRAVERSER_H_INCLUDED_3127463214871234 +#define FOLDER_TRAVERSER_H_INCLUDED_3127463214871234 #include +#include #include "zstring.h" -#include "file_id_def.h" - -//advanced file traverser returning metadata and hierarchical information on files and directories namespace zen { -struct TraverseCallback +struct FileInfo { - virtual ~TraverseCallback() {} - - struct SymlinkInfo - { - SymlinkInfo() : lastWriteTime() {} - - std::int64_t lastWriteTime; //number of seconds since Jan. 1st 1970 UTC - }; - - struct FileInfo - { - FileInfo() : fileSize(), lastWriteTime(), symlinkInfo() {} - - std::uint64_t fileSize; //unit: bytes! - std::int64_t lastWriteTime; //number of seconds since Jan. 1st 1970 UTC - FileId id; //optional: initial if not supported! - const SymlinkInfo* symlinkInfo; //only filled if file is a followed symlink - }; - - enum HandleLink - { - LINK_FOLLOW, //dereferences link, then calls "onDir()" or "onFile()" - LINK_SKIP - }; - - enum HandleError - { - ON_ERROR_RETRY, - ON_ERROR_IGNORE - }; + const Zchar* shortName; + const Zstring& fullPath; + std::uint64_t fileSize; //[bytes] + std::int64_t lastWriteTime; //number of seconds since Jan. 1st 1970 UTC +}; - virtual void onFile (const Zchar* shortName, const Zstring& filepath, const FileInfo& details) = 0; - virtual HandleLink onSymlink(const Zchar* shortName, const Zstring& linkpath, const SymlinkInfo& details) = 0; - virtual TraverseCallback* onDir (const Zchar* shortName, const Zstring& dirpath) = 0; - //nullptr: ignore directory, non-nullptr: traverse into using the (new) callback => implement releaseDirTraverser() if necessary! - virtual void releaseDirTraverser(TraverseCallback* trav) {} +struct DirInfo +{ + const Zchar* shortName; + const Zstring& fullPath; +}; - virtual HandleError reportDirError (const std::wstring& msg, size_t retryNumber) = 0; //failed directory traversal -> consider directory data at current level as incomplete! - virtual HandleError reportItemError(const std::wstring& msg, size_t retryNumber, const Zchar* shortName) = 0; //failed to get data for single file/dir/symlink only! +struct SymlinkInfo +{ + const Zchar* shortName; + const Zstring& fullPath; + std::int64_t lastWriteTime; //number of seconds since Jan. 1st 1970 UTC }; -//custom traverser with detail information about files -//- client needs to handle duplicate file reports! (FilePlusTraverser fallback, retrying to read directory contents, ...) -//- directory may end with PATH_SEPARATOR -void traverseFolder(const Zstring& dirpath, TraverseCallback& sink); //noexcept +//- non-recursive +//- directory path may end with PATH_SEPARATOR +void traverseFolder(const Zstring& dirPath, //noexcept + const std::function& onFile, // + const std::function& onDir, //optional + const std::function& onLink, // + const std::function& onError); // } -#endif // FILETRAVERSER_H_INCLUDED +#endif //FOLDER_TRAVERSER_H_INCLUDED_3127463214871234 -- cgit