# # patch "ChangeLog" # from [02053df84d062b603775545ec849769e6c50a330] # to [fceff6f8f84a3516265794b9bcf540b02854b1c1] # # patch "file_io.cc" # from [5fe6cd7ba1fa59cc6c18b29ff09c8abbd7e8eedc] # to [17fb90ea9f1ab88b9178533ad6155a38abedee5b] # # patch "platform.hh" # from [172401a0e586b00a72d723da7f2ce41b6d89633a] # to [0c8532e0798d470031bc897517234e3c8f4b9be9] # # patch "unix/fs.cc" # from [634186c75555e7f8bf90e66fb114708f6573398a] # to [d8d77413b5d049471371f97adb450b4d6a9e6780] # # patch "win32/fs.cc" # from [669575064c36c2e645252587a79b1957ddb4be9f] # to [c9a82e276c7420d31f928c439dc545acd2a6b209] # ======================================================================== --- ChangeLog 02053df84d062b603775545ec849769e6c50a330 +++ ChangeLog fceff6f8f84a3516265794b9bcf540b02854b1c1 @@ -1,5 +1,12 @@ 2005-08-25 Nathaniel Smith + * platform.hh (get_path_status): New function. + * unix/fs.cc (get_path_status): Implement. + * win32/fs.cc (get_path_status): Implement inefficiently (does + win32 have stat?) + +2005-08-25 Nathaniel Smith + * file_io.cc (get_homedir, tilde_expand, book_keeping_file) (book_keeping_dir): Remove. ======================================================================== --- file_io.cc 5fe6cd7ba1fa59cc6c18b29ff09c8abbd7e8eedc +++ file_io.cc 17fb90ea9f1ab88b9178533ad6155a38abedee5b @@ -37,20 +37,13 @@ bool -directory_exists(local_path const & p) +directory_exists(any_path const & p) { - return fs::exists(localized(p)) && - fs::is_directory(localized(p)); + return fs::exists(p.as_external()) && + fs::is_directory(p.as_external()); } bool -directory_exists(file_path const & p) -{ - return fs::exists(localized(p)) && - fs::is_directory(localized(p)); -} - -bool file_exists(file_path const & p) { return fs::exists(localized(p)); ======================================================================== --- platform.hh 172401a0e586b00a72d723da7f2ce41b6d89633a +++ platform.hh 0c8532e0798d470031bc897517234e3c8f4b9be9 @@ -54,4 +54,10 @@ void change_current_working_dir(any_path const & to); utf8 tilde_expand(utf8 const & path); utf8 get_homedir(); +namespace path +{ + typedef enum { nonexistent, directory, file } status; +}; +path::status get_path_status(any_path const & path); + #endif // __PLATFORM_HH__ ======================================================================== --- unix/fs.cc 634186c75555e7f8bf90e66fb114708f6573398a +++ unix/fs.cc d8d77413b5d049471371f97adb450b4d6a9e6780 @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -75,3 +76,27 @@ return tmp; } + +path::status +get_path_status(any_path const & path) +{ + struct stat buf; + int res; + res = stat(path.as_external().c_str(), &buf); + if (res < 0) + { + if (errno == ENOENT) + return path::nonexistent; + else + E(false, F("error accessing file %s: %s") % path % strerror(errno)); + } + if (S_ISREG(buf.st_mode)) + return path::file; + else if (S_ISDIR(buf.st_mode)) + return path::directory; + else + { + // fifo or device or who knows what... + E(false, F("cannot handle special file %s") % path); + } +} ======================================================================== --- win32/fs.cc 669575064c36c2e645252587a79b1957ddb4be9f +++ win32/fs.cc c9a82e276c7420d31f928c439dc545acd2a6b209 @@ -10,6 +10,7 @@ #include #include +#include "vocab.hh" #include "sanity.hh" #include "platform.hh" @@ -98,3 +99,15 @@ return tmp.string(); } + +path::status +get_path_status(any_path const & path) +{ + fs::path p(path.as_external(), fs::native); + if (!fs::exists(p)) + return path::nonexistent; + else if (fs::is_directory(p)) + return path::directory; + else + return path::file; +}