fs::path relative_path(const fs::path& inFromDir, const fs::path& inFile) { // assert(false); fs::path::iterator d = inFromDir.begin(); fs::path::iterator f = inFile.begin(); while (d != inFromDir.end() and f != inFile.end() and *d == *f) { ++d; ++f; } fs::path result; if (d == inFromDir.end() and f == inFile.end()) result = "."; else { while (d != inFromDir.end()) { result /= ".."; ++d; } while (f != inFile.end()) { result /= *f; ++f; } } return result; }
fs::path path_difference(fs::path const& outdir, fs::path const& path) { fs::path outtmp, temp; fs::path::iterator out = outdir.begin(), file = path.begin(); for(; out != outdir.end() && file != path.end(); ++out, ++file) { if(!fs::equivalent(outtmp /= *out, temp /= *file)) break; } out = (out == outdir.begin()) ? outdir.end() : out; fs::path result = fs::path(); for(; out != outdir.end(); ++out) if(*out != ".") result /= ".."; std::divides<fs::path> concat; return std::accumulate(file, path.end(), result, concat); }
fs::path Path::MakeRelative(fs::path const& path, fs::path const& base) const { if (path.empty() || base.empty()) return path; const auto str = path.string(); if (boost::starts_with(str, "?dummy") || boost::starts_with(str, "dummy-audio:")) return path; // Paths on different volumes can't be made relative to each other if (path.has_root_name() && path.root_name() != base.root_name()) return path.string(); auto path_it = path.begin(); auto ref_it = base.begin(); for (; path_it != path.end() && ref_it != base.end() && *path_it == *ref_it; ++path_it, ++ref_it) ; agi::fs::path result; for (; ref_it != base.end(); ++ref_it) result /= ".."; for (; path_it != path.end(); ++path_it) result /= *path_it; return result; }
void file_storage::add_file(fs::path const& file, size_type size, int flags , std::time_t mtime, fs::path const& symlink_path) { TORRENT_ASSERT(size >= 0); #if BOOST_VERSION < 103600 if (!file.has_branch_path()) #else if (!file.has_parent_path()) #endif { // you have already added at least one file with a // path to the file (branch_path), which means that // all the other files need to be in the same top // directory as the first file. TORRENT_ASSERT(m_files.empty()); m_name = file.string(); } else { if (m_files.empty()) m_name = *file.begin(); } TORRENT_ASSERT(m_name == *file.begin()); m_files.push_back(file_entry()); file_entry& e = m_files.back(); e.size = size; e.path = file; e.offset = m_total_size; e.pad_file = bool(flags & pad_file); e.hidden_attribute = bool(flags & attribute_hidden); e.executable_attribute = bool(flags & attribute_executable); e.symlink_attribute = bool(flags & attribute_symlink); if (e.symlink_attribute) e.symlink_path = symlink_path.string(); e.mtime = mtime; m_total_size += size; }
bool can::is_in_home(const fs::path& file) { fs::path home{user::current().get_HOME()}; for (auto it = home.begin(), file_it = file.begin(); it != home.end() && file_it != file.end(); it++, file_it++) { if (*it != *file_it) { return false; } } return true; }
void MResourceFileImp::AddEntry( fs::path inPath, const char* inData, uint32 inSize) { uint32 node = 0; // start at root for (fs::path::iterator p = inPath.begin(); p != inPath.end(); ++p) { // no such child? Add it and continue if (mIndex[node].mChild == 0) { MResourceImp child = {}; child.mName = mName.size(); copy(p->begin(), p->end(), back_inserter(mName)); mName.push_back(0); mIndex[node].mChild = mIndex.size(); mIndex.push_back(child); node = mIndex[node].mChild; continue; } // lookup the path element in the current directory uint32 next = mIndex[node].mChild; for (;;) { const char* name = &mName[0] + mIndex[next].mName; // if this is the one we're looking for, break out of the loop if (*p == name) { node = next; break; } // if there is a next element, loop if (mIndex[next].mNext != 0) { next = mIndex[next].mNext; continue; } // not found, create it MResourceImp n = {}; n.mName = mName.size(); copy(p->begin(), p->end(), back_inserter(mName)); mName.push_back(0); node = mIndex.size(); mIndex[next].mNext = node; mIndex.push_back(n); break; } } assert(node != 0); assert(node < mIndex.size()); mIndex[node].mSize = inSize; mIndex[node].mData = mData.size(); copy(inData, inData + inSize, back_inserter(mData)); while ((mData.size() % 8) != 0) mData.push_back('\0'); }