int extractToFile(const std::string& filename, ZipEntry& info) { int err = UNZ_ERRNO; /* If zip entry is a directory then create it on disk */ makedir(parentDirectory(filename)); /* Create the file on disk so we can unzip to it */ std::ofstream output_file(filename.c_str(), std::ofstream::binary); if (output_file.good()) { if (extractToStream(output_file, info)) err = UNZ_OK; output_file.close(); /* Set the time of the file that has been unzipped */ tm_unz timeaux; memcpy(&timeaux, &info.unixdate, sizeof(timeaux)); changeFileDate(filename, info.dosdate, timeaux); } else output_file.close(); return err; }
int encfs_mkdir(const char *path, mode_t mode) { fuse_context *fctx = fuse_get_context(); EncFS_Context *ctx = context(); if (isReadOnly(ctx)) return -EROFS; int res = -EIO; std::shared_ptr<DirNode> FSRoot = ctx->getRoot(&res); if (!FSRoot) return res; try { uid_t uid = 0; gid_t gid = 0; if (ctx->publicFilesystem) { uid = fctx->uid; gid = fctx->gid; } res = FSRoot->mkdir(path, mode, uid, gid); // Is this error due to access problems? if (ctx->publicFilesystem && -res == EACCES) { // try again using the parent dir's group string parent = parentDirectory(path); std::shared_ptr<FileNode> dnode = FSRoot->lookupNode(parent.c_str(), "mkdir"); struct stat st; if (dnode->getAttr(&st) == 0) res = FSRoot->mkdir(path, mode, uid, st.st_gid); } } catch (encfs::Error &err) { RLOG(ERROR) << "error caught in mkdir: " << err.what(); } return res; }
void recTree(std::string currentPath, std::set<std::string>& fullList, const std::string& exportroot) { if (fileExists(currentPath.c_str())) { // fs::path bRoot(exportroot); // fs::path bPath(currentPath); std::string stripstr = currentPath.substr(exportroot.length()); // LOGI((std::string("recTree: ") + stripstr).c_str()); fullList.insert(stripstr); if (isDirectory(currentPath.c_str())) { // fs::is_directory(bPath.string())) { DIR* d; if (currentPath.at(currentPath.length() - 1) != '/') currentPath += "/"; // LOGI((std::string("currentPath: ") + currentPath).c_str()); if ((d = opendir(currentPath.c_str())) == NULL) return; struct dirent* de; while ((de = readdir(d)) != NULL) { std::string path = currentPath; if (std::string(de->d_name) != "." && std::string(de->d_name) != "..") { path += std::string(de->d_name); // LOGI((std::string("path: ") + path).c_str()); recTree(path, fullList, exportroot); } } closedir(d); } else { // currentPath ends with "/" std::string parent = parentDirectory(currentPath); if (parent == "") { // Add parent dirs of current file down to root while (parent != exportroot) { std::string strippar = parent.substr(exportroot.length()); fullList.insert(strippar); // LOGI((std::string("Adding parent ") + parent.string()).c_str()); parent = parentDirectory(parent); } } } } }
void OutputDirectory::createTag (UNUSED const std::string& tag) const { ASSERT (tag != ""); ASSERT (tag.find ('/') == std::string::npos); ASSERT (tag[0] != '.'); ASSERT (tag.substr (0, 7) != "output_"); #if OS_UNIX boost::filesystem::path link = parentDirectory () / tag; Core::Error::checkIgnore ("unlink", unlink (link.BOOST_FILE_STRING.c_str ()), ENOENT); Core::Error::check ("symlink", symlink (name ().c_str (), link.BOOST_FILE_STRING.c_str ())); #endif }
int PluginPackage::compare(const PluginPackage& compareTo) const { // Sort plug-ins that allow multiple instances first. bool AallowsMultipleInstances = !quirks().contains(PluginQuirkDontAllowMultipleInstances); bool BallowsMultipleInstances = !compareTo.quirks().contains(PluginQuirkDontAllowMultipleInstances); if (AallowsMultipleInstances != BallowsMultipleInstances) return AallowsMultipleInstances ? -1 : 1; // Sort plug-ins in a preferred path first. bool AisInPreferredDirectory = PluginDatabase::isPreferredPluginDirectory(parentDirectory()); bool BisInPreferredDirectory = PluginDatabase::isPreferredPluginDirectory(compareTo.parentDirectory()); if (AisInPreferredDirectory != BisInPreferredDirectory) return AisInPreferredDirectory ? -1 : 1; int diff = strcmp(name().utf8().data(), compareTo.name().utf8().data()); if (diff) return diff; if (diff = compareFileVersion(compareTo.version())) return diff; return strcmp(parentDirectory().utf8().data(), compareTo.parentDirectory().utf8().data()); }
/** * @brief Retrieves the absolute path of a given directory * @param directoryEntry * @param buf is a buffer big enough to hold the absolute path */ void absoluteDirectoryPath(DIRENTRY* directoryEntry, char* buf) { // if there is no parent directory, we are at root level DIRENTRY* parent = parentDirectory(directoryEntry); if(parent == 0) { sprintf(buf, "\\"); return; } // if we are not at root level, fire up the recursion absoluteDirectoryPath(parent, buf); // concatenate the path until here and this directory's name unsigned short stringLength = strlen(buf); char dirname[512]; currentFolderName(directoryEntry, dirname); sprintf(&buf[stringLength], "\\%s", dirname); }
/** * @brief Retrieves the current folder's name (handy if you only have a '.' entry at hand) * @param currentDirectoryEntry * @param buf is a buffer big enough to hold the folder name */ void currentFolderName(DIRENTRY* currentDirectoryEntry, char* buf) { DIRENTRY* directoryEntry; DIRENTRY* parentDirectoryEntry = 0; parentDirectoryEntry = parentDirectory(currentDirectoryEntry); // read parent directory, find entry that matches current (original) folder's first cluster lseek(handle, getclusteroffset(parentDirectoryEntry->firstcluser), SEEK_SET); while(directoryEntry = readDirectoryEntry()) { if(directoryEntry->firstcluser == currentDirectoryEntry->firstcluser) { formatDirectoryEntryName(directoryEntry, buf); return; } } }
string FileNode::plaintextParent() const { return parentDirectory(_pname); }