#pragma once #include #include #include #include #include #include #include #include #ifdef _win32_ #include #include #include #include #include #include "dirent_win.h" // these live in mktemp_system.cpp extern "C" int mkstemps(char* path, int slen); char* mkdtemp(char* path); #else #ifdef _sun_ #include char* mkdtemp(char* path); #endif #include #include #include #ifndef DT_DIR #include #endif #endif bool IsDir(const TString& path); int mkpath(char* path, int mode = 0777); TString GetHomeDir(); void MakeDirIfNotExist(const char* path, int mode = 0777); inline void MakeDirIfNotExist(const TString& path, int mode = 0777) { MakeDirIfNotExist(path.data(), mode); } /// Create path making parent directories as needed void MakePathIfNotExist(const char* path, int mode = 0777); void SlashFolderLocal(TString& folder); bool correctpath(TString& filename); bool resolvepath(TString& folder, const TString& home); char GetDirectorySeparator(); const char* GetDirectorySeparatorS(); void RemoveDirWithContents(TString dirName); const char* GetFileNameComponent(const char* f); inline TString GetFileNameComponent(const TString& f) { return GetFileNameComponent(f.data()); } /// RealPath doesn't guarantee trailing separator to be stripped or left in place for directories. TString RealPath(const TString& path); // throws TString RealLocation(const TString& path); /// throws; last file name component doesn't need to exist TString GetSystemTempDir(); int MakeTempDir(char path[/*FILENAME_MAX*/], const char* prefix); int ResolvePath(const char* rel, const char* abs, char res[/*FILENAME_MAX*/], bool isdir = false); TString ResolvePath(const char* rel, const char* abs, bool isdir = false); TString ResolvePath(const char* path, bool isDir = false); TString ResolveDir(const char* path); bool SafeResolveDir(const char* path, TString& result); TString GetDirName(const TString& path); TString GetBaseName(const TString& path); TString StripFileComponent(const TString& fileName); class TExistenceChecker { public: TExistenceChecker(bool strict = false) : Strict(strict) { } void SetStrict(bool strict) { Strict = strict; } bool IsStrict() const { return Strict; } const char* Check(const char* fname) const { if (!fname || !*fname) return nullptr; if (Strict) { NFs::EnsureExists(fname); } else if (!NFs::Exists(fname)) fname = nullptr; return fname; } private: bool Strict; };