# # # patch "paths.cc" # from [25f4a2179cd30659a62cb5f467dba2214fbdef30] # to [f0ef9bdb3ec64caa3183cb482ff62c3fdd9b1314] # # patch "platform-wrapped.hh" # from [571fae420ef32c370127b56311cba9fc49819237] # to [70c1cf6a373352fa802cf407d354cf2caad92754] # # patch "unix/fs.cc" # from [fe1c5d9156a335af645d9d3a1bffb7db1d9c13c7] # to [65223d21b27af21c1431b2ff1ef4e67d4a8428ee] # # patch "win32/fs.cc" # from [23054bb5ccc3f86053acf706610e941468679631] # to [197cf91013ff1a44665ce6cecd5aea9180c8f418] # ============================================================ --- paths.cc 25f4a2179cd30659a62cb5f467dba2214fbdef30 +++ paths.cc f0ef9bdb3ec64caa3183cb482ff62c3fdd9b1314 @@ -604,7 +604,7 @@ static inline string const_system_path(u static inline string const_system_path(utf8 const & path) { N(!path().empty(), F("invalid path ''")); - string expanded = tilde_expand(path)(); + string expanded = tilde_expand(path()); if (is_absolute_here(expanded)) return normalize_out_dots(expanded); else ============================================================ --- platform-wrapped.hh 571fae420ef32c370127b56311cba9fc49819237 +++ platform-wrapped.hh 70c1cf6a373352fa802cf407d354cf2caad92754 @@ -5,11 +5,6 @@ #include "platform.hh" #include "vocab.hh" -inline utf8 tilde_expand(utf8 const & path) -{ - return utf8(tilde_expand(path())); -} - inline void change_current_working_dir(any_path const & to) { change_current_working_dir(to.as_external()); ============================================================ --- unix/fs.cc fe1c5d9156a335af645d9d3a1bffb7db1d9c13c7 +++ unix/fs.cc 65223d21b27af21c1431b2ff1ef4e67d4a8428ee @@ -15,32 +15,28 @@ #include #include -#include -#include -#include - #include "sanity.hh" #include "platform.hh" -namespace fs = boost::filesystem; +using std::string; -std::string +string get_current_working_dir() { char buffer[4096]; E(getcwd(buffer, 4096), F("cannot get working directory: %s") % os_strerror(errno)); - return std::string(buffer); + return string(buffer); } void -change_current_working_dir(std::string const & to) +change_current_working_dir(string const & to) { E(!chdir(to.c_str()), F("cannot change to directory %s: %s") % to % os_strerror(errno)); } -std::string +string get_default_confdir() { return get_homedir() + "/.monotone"; @@ -49,56 +45,54 @@ get_default_confdir() // FIXME: BUG: this probably mangles character sets // (as in, we're treating system-provided data as utf8, but it's probably in // the filesystem charset) -std::string +string get_homedir() { char * home = getenv("HOME"); if (home != NULL) - return std::string(home); + return string(home); struct passwd * pw = getpwuid(getuid()); N(pw != NULL, F("could not find home directory for uid %d") % getuid()); - return std::string(pw->pw_dir); + return string(pw->pw_dir); } -std::string -tilde_expand(std::string const & in) +string +tilde_expand(string const & in) { if (in.empty() || in[0] != '~') return in; - fs::path tmp(in, fs::native); - fs::path::iterator i = tmp.begin(); - if (i != tmp.end()) + if (in.size() == 1) // just ~ + return get_homedir(); + if (in[1] == '/') // ~/... + return get_homedir() + in.substr(1); + + string user, after; + string::size_type slashpos = in.find('/'); + if (slashpos == string::npos) { - fs::path res; - if (*i == "~") - { - fs::path restmp(get_homedir(), fs::native); - res /= restmp; - ++i; - } - else if (i->size() > 1 && i->at(0) == '~') - { - struct passwd * pw; - // FIXME: BUG: this probably mangles character sets (as in, we're - // treating system-provided data as utf8, but it's probably in the - // filesystem charset) - pw = getpwnam(i->substr(1).c_str()); - N(pw != NULL, - F("could not find home directory for user %s") % i->substr(1)); - res /= std::string(pw->pw_dir); - ++i; - } - while (i != tmp.end()) - res /= *i++; - return res.string(); + user = in.substr(1); + after = ""; } + else + { + user = in.substr(1, slashpos-1); + after = in.substr(slashpos); + } - return tmp.string(); + struct passwd * pw; + // FIXME: BUG: this probably mangles character sets (as in, we're + // treating system-provided data as utf8, but it's probably in the + // filesystem charset) + pw = getpwnam(user.c_str()); + N(pw != NULL, + F("could not find home directory for user %s") % user); + + return string(pw->pw_dir) + after; } path::status -get_path_status(std::string const & path) +get_path_status(string const & path) { struct stat buf; int res; @@ -122,7 +116,7 @@ void } void -rename_clobberingly(std::string const & from, std::string const & to) +rename_clobberingly(string const & from, string const & to) { E(!rename(from.c_str(), to.c_str()), F("renaming '%s' to '%s' failed: %s") % from % to % os_strerror(errno)); @@ -141,7 +135,7 @@ static int // files from 62**6 to 36**6, oh noes. static int -make_temp_file(std::string const & dir, std::string & name, mode_t mode) +make_temp_file(string const & dir, string & name, mode_t mode) { static const char letters[] = "abcdefghijklmnopqrstuvwxyz0123456789"; @@ -151,7 +145,7 @@ make_temp_file(std::string const & dir, static u32 value; struct timeval tv; - std::string tmp = dir + "/mtxxxxxx.tmp"; + string tmp = dir + "/mtxxxxxx.tmp"; gettimeofday(&tv, 0); value += ((u32) tv.tv_usec << 16) ^ tv.tv_sec ^ getpid(); @@ -210,9 +204,9 @@ void // will be passed mode 0600 or 0666 -- the actual permissions are modified // by umask as usual). void -write_data_worker(std::string const & fname, - std::string const & dat, - std::string const & tmpdir, +write_data_worker(string const & fname, + string const & dat, + string const & tmpdir, bool user_private) { struct auto_closer @@ -222,7 +216,7 @@ write_data_worker(std::string const & fn ~auto_closer() { close(fd); } }; - std::string tmp; + string tmp; int fd = make_temp_file(tmpdir, tmp, user_private ? 0600 : 0666); { @@ -260,10 +254,10 @@ write_data_worker(std::string const & fn rename_clobberingly(tmp, fname); } -std::string +string get_locale_dir() { - return std::string(LOCALEDIR); + return string(LOCALEDIR); } // Local Variables: ============================================================ --- win32/fs.cc 23054bb5ccc3f86053acf706610e941468679631 +++ win32/fs.cc 197cf91013ff1a44665ce6cecd5aea9180c8f418 @@ -12,15 +12,9 @@ #include #include -#include -#include -#include - #include "sanity.hh" #include "platform.hh" -namespace fs = boost::filesystem; - std::string get_current_working_dir() { @@ -108,32 +102,40 @@ tilde_expand(std::string const & in) { if (in.empty() || in[0] != '~') return in; - fs::path tmp(in, fs::native); - fs::path::iterator i = tmp.begin(); - if (i != tmp.end()) - { - fs::path res; - if (*i == "~" || i->size() > 1 && i->at(0) == '~') - { - fs::path restmp(get_homedir(), fs::native); - res /= restmp; - ++i; - } - while (i != tmp.end()) - res /= *i++; - return res.string(); - } - return tmp.string(); + // just ~ + if (in.size() == 1) + return get_homedir(); + + // ~/foo, ~\foo + if (in[1] == '/' || in[1] == '\\') + return get_homedir() + in.substr(1); + + // We don't support ~name on Windows. + return in; } path::status get_path_status(std::string const & path) { - fs::path p(path, fs::native); - if (!fs::exists(p)) - return path::nonexistent; - else if (fs::is_directory(p)) + DWORD attrs = GetFileAttributesA(path.c_str()); + + if (attrs == INVALID_FILE_ATTRIBUTES) + { + uint err = GetLastError(); + // this list of errors that mean the path doesn't exist borrowed from + // boost 1.33.1, with unnecessary parenthesis removal by zack + if(err == ERROR_FILE_NOT_FOUND + || err == ERROR_INVALID_PARAMETER + || err == ERROR_NOT_READY + || err == ERROR_PATH_NOT_FOUND + || err == ERROR_INVALID_NAME + || err == ERROR_BAD_NETPATH) + return path::nonexistent; + + E(F("%s: GetFileAttributes error: %s") % path % os_strerror(err)); + } + else if (attrs & FILE_ATTRIBUTE_DIRECTORY) return path::directory; else return path::file;