# # patch "ChangeLog" # from [d6e8452afbee68a21596c2a191f9e0d2d57c3ad1] # to [02053df84d062b603775545ec849769e6c50a330] # # patch "file_io.cc" # from [bf552b49ffcb68e946a2ca83d5441a7477b1ff3a] # to [5fe6cd7ba1fa59cc6c18b29ff09c8abbd7e8eedc] # ======================================================================== --- ChangeLog d6e8452afbee68a21596c2a191f9e0d2d57c3ad1 +++ ChangeLog 02053df84d062b603775545ec849769e6c50a330 @@ -1,5 +1,10 @@ 2005-08-25 Nathaniel Smith + * file_io.cc (get_homedir, tilde_expand, book_keeping_file) + (book_keeping_dir): Remove. + +2005-08-25 Nathaniel Smith + * platform.hh (get_homedir): New function. * {win32,unix}/fs.cc (get_homedir): Expose. ======================================================================== --- file_io.cc bf552b49ffcb68e946a2ca83d5441a7477b1ff3a +++ file_io.cc 5fe6cd7ba1fa59cc6c18b29ff09c8abbd7e8eedc @@ -21,115 +21,6 @@ using namespace std; -string const book_keeping_dir("MT"); - - -string -get_homedir() -{ -#ifdef WIN32 - // Windows is fun! - // See thread on monotone-devel: - // Message-Id: - // URL: http://lists.gnu.org/archive/html/monotone-devel/2005-02/msg00241.html - char * home; - L(F("Searching for home directory\n")); - // First try MONOTONE_HOME, to give people a way out in case the cruft below - // doesn't work for them. - home = getenv("MONOTONE_HOME"); - if (home != NULL) - { - L(F("Home directory from MONOTONE_HOME\n")); - return string(home); - } - // If running under cygwin or mingw, try HOME next: - home = getenv("HOME"); - char * ostype = getenv("OSTYPE"); - if (home != NULL - && ostype != NULL - && (string(ostype) == "cygwin" || string(ostype) == "msys")) - { - L(F("Home directory from HOME\n")); - return string(home); - } - // Otherwise, try USERPROFILE: - home = getenv("USERPROFILE"); - if (home != NULL) - { - L(F("Home directory from USERPROFILE\n")); - return string(home); - } - // Finally, if even that doesn't work (old version of Windows, I think?), - // try the HOMEDRIVE/HOMEPATH combo: - char * homedrive = getenv("HOMEDRIVE"); - char * homepath = getenv("HOMEPATH"); - if (homedrive != NULL && homepath != NULL) - { - L(F("Home directory from HOMEDRIVE+HOMEPATH\n")); - return string(homedrive) + string(homepath); - } - // And if things _still_ didn't work, give up. - N(false, F("could not find home directory (tried MONOTONE_HOME, HOME (if " - "cygwin/mingw), USERPROFILE, HOMEDRIVE/HOMEPATH")); -#else - char * home = getenv("HOME"); - if (home != NULL) - return string(home); - - struct passwd * pw = getpwuid(getuid()); - N(pw != NULL, F("could not find home directory for uid %d") % getuid()); - return string(pw->pw_dir); -#endif -} - -string -tilde_expand(string const & path) -{ - fs::path tmp = mkpath(path); - fs::path::iterator i = tmp.begin(); - if (i != tmp.end()) - { - fs::path res; - if (*i == "~") - { - res /= mkpath(get_homedir()); - ++i; - } - else if (i->size() > 1 && i->at(0) == '~') - { -#ifdef WIN32 - res /= mkpath(get_homedir()); -#else - struct passwd * pw; - pw = getpwnam(i->substr(1).c_str()); - N(pw != NULL, F("could not find home directory for user %s") % i->substr(1)); - res /= mkpath(string(pw->pw_dir)); -#endif - ++i; - } - while (i != tmp.end()) - res /= mkpath(*i++); - return res.string(); - } - - return tmp.string(); -} - -static bool -book_keeping_file(fs::path const & p) -{ - return *(p.begin()) == book_keeping_dir; -} - -bool -book_keeping_file(local_path const & p) -{ - if (p() == book_keeping_dir) return true; - if (*(mkpath(p()).begin()) == book_keeping_dir) return true; - return false; -} - - // A path::state can be used as a boolean context for exists/doesn't exist, // or can be used in a switch statement to consider all possibilities. namespace path