diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2012-02-19 21:19:11 +0900 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2012-02-19 21:19:11 +0900 |
| commit | 075ea06ad78509bf23023711c37adec2faf1a3ce (patch) | |
| tree | 5c174c31d6c7509987e4c7a15dab2db6ec302b22 /src/File.cc | |
| parent | b7dbcea58bf0fea8792a653a64d8a87ae584d839 (diff) | |
Supported Windows UNC path.
Diffstat (limited to 'src/File.cc')
| -rw-r--r-- | src/File.cc | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/src/File.cc b/src/File.cc index 87b95486..7a73f503 100644 --- a/src/File.cc +++ b/src/File.cc @@ -122,13 +122,43 @@ bool File::mkdirs() { *i = '/'; } } + std::string::iterator dbegin; + if(util::startsWith(path, "//")) { + // UNC path + std::string::size_type hostEnd = path.find('/', 2); + if(hostEnd == std::string::npos) { + // UNC path with only hostname considered as an error. + return false; + } else if(hostEnd == 2) { + // If path starts with "///", it is not considered as UNC. + dbegin = path.begin(); + } else { + std::string::iterator i = path.begin()+hostEnd; + std::string::iterator eoi = path.end(); + // //host/mount/dir/... + // | | + // i (at this point) + // | + // dbegin (will be) + // Skip to after first directory part. This is because + // //host/dir appears to be non-directory and mkdir it fails. + for(; i != eoi && *i == '/'; ++i); + for(; i != eoi && *i != '/'; ++i); + dbegin = i; + A2_LOG_DEBUG(fmt("UNC Prefix %s", + std::string(path.begin(), dbegin).c_str())); + } + } else { + dbegin = path.begin(); + } std::string::iterator begin = path.begin(); std::string::iterator end = path.end(); + for(std::string::iterator i = dbegin; i != end;) { #else // !__MINGW32__ std::string::iterator begin = name_.begin(); std::string::iterator end = name_.end(); -#endif // !__MINGW32__ for(std::string::iterator i = begin; i != end;) { +#endif // !__MINGW32__ std::string::iterator j = std::find(i, end, '/'); if(std::distance(i, j) == 0) { ++i; |
