static void link_new(struct dir_info *parent, const char *name, struct file_info *file) { struct dir_entry_info *entry; char *path, *target; int ret; if (!file) return; entry = file->links; if (!entry) return; path = dir_path(parent, name); target = dir_path(entry->parent, entry->name); ret = link(target, path); if (ret == -1) { CHECK(errno == ENOSPC); free(target); free(path); full = 1; return; } free(target); free(path); add_dir_entry(parent, 'f', name, file); }
static char *pick_symlink_target(const char *symlink_path) { struct dir_info *dir; struct dir_entry_info *entry; size_t r; char *path, *rel_path; dir = pick_dir(); if (tests_random_no(100) < 10) return dir_path(dir, make_name(dir)); r = tests_random_no(dir->number_of_entries); entry = dir->first; while (entry && r) { entry = entry->next; --r; } if (!entry) entry = dir->first; if (!entry) return dir_path(dir, make_name(dir)); path = dir_path(dir, entry->name); if (tests_random_no(20) < 10) return path; rel_path = relative_path(symlink_path, path); free(path); return rel_path; }
void dir_destroy(Dir *d) { //fprintf(stderr, "Destroying dir %s\n", dir_path(d)); int res = rmdir(dir_path(d)); if (res != 0 && errno != ENOENT) { perror(dir_path(d)); } }
Dir *dir_create(Dir *parent, int num) { // Allocate directory Dir *d = malloc(sizeof(Dir)); if (d == NULL) { perror("dir_create() malloc"); exit(1); } list_init(&d->list); d->parent = parent; d->name[0] = 'd'; d->name[1] = '0' + num / 10; d->name[2] = '0' + num % 10; d->name[3] = 0; d->num_files = 0; // Create directory in filesystem //fprintf(stderr, "Creating dir %s\n", dir_path(d)); if (mkdir(dir_path(d), 0700) != 0) { perror(dir_path(d)); exit(1); } // Link into dir list and add to active list list_add_after(&root_dir.list, &d->list); vector_add(active_dirs, d); // Create subdirs while(--num > 0) { (void)dir_create(d, num); } // All done, return directory return d; }
static void dir_remove(struct dir_info *dir) { char *path; /* Remove directory contents */ while (dir->first) { struct dir_entry_info *entry; entry = dir->first; if (entry->type == 'd') dir_remove(entry->entry.dir); else if (entry->type == 'f') file_unlink(entry); else if (entry->type == 's') symlink_remove(entry->entry.symlink); else CHECK(0); /* Invalid struct dir_entry_info */ } /* Remove entry from parent directory */ remove_dir_entry(dir->entry); /* Remove directory itself */ path = dir_path(dir->parent, dir->name); CHECK(rmdir(path) != -1); free(dir); }
static struct dir_info *dir_new(struct dir_info *parent, const char *name) { struct dir_info *dir; size_t sz; char *path; path = dir_path(parent, name); if (mkdir(path, 0777) == -1) { CHECK(errno == ENOSPC); full = 1; free(path); return NULL; } free(path); sz = sizeof(struct dir_info); dir = (struct dir_info *) malloc(sz); CHECK(dir != NULL); memset(dir, 0, sz); dir->name = copy_string(name); dir->parent = parent; if (parent) add_dir_entry(parent, 'd', name, dir); return dir; }
void symlink_check(const struct symlink_info *symlink) { char *path, buf[8192], *target; struct stat st1, st2; ssize_t len; int ret1, ret2; path = dir_path(symlink->entry->parent, symlink->entry->name); CHECK(lstat(path, &st1) != -1); CHECK(S_ISLNK(st1.st_mode)); CHECK(st1.st_nlink == 1); len = readlink(path, buf, 8192); CHECK(len > 0 && len < 8192); buf[len] = '\0'; CHECK(strlen(symlink->target_pathname) == len); CHECK(strncmp(symlink->target_pathname, buf, len) == 0); /* Check symlink points where it should */ ret1 = stat(path, &st1); target = symlink_path(path, symlink->target_pathname); ret2 = stat(target, &st2); CHECK(ret1 == ret2); if (ret1 != -1) { CHECK(st1.st_dev == st2.st_dev); CHECK(st1.st_ino == st2.st_ino); } free(target); free(path); }
void findModels(std::string dirname) { fs::path dir_path(dirname); if (!fs::exists(dir_path)) { std::cerr << "ERROR: path does not exist: " << dirname << std::endl; gScene = static_cast<OSG::Node *>(NULL); OSG::osgExit(); exit(-1); } fs::directory_iterator end_itr; for(fs::directory_iterator itr(dir_path); itr != end_itr; ++itr) { if(!fs::is_directory(*itr)) { if (fs::extension(*itr) == std::string(".osb") || fs::extension(*itr) == std::string(".wrl")) { fs::path complete_file = fs::complete(*itr); std::string filename(complete_file.string()); std::cout << "Found file: " << filename << std::endl; OSG::ModelRequestPtr req = OSG::ModelRequest::create()->init(OSG::NodeRefPtr(gScene.node()), filename); OSG::BackgroundLoader::the()->addRequest(req); } } } }
void CommonPath::SetCwd(std::string& sPath) { std::wstring sPathW = StringUtils::Utf8_To_wstring(sPath); boost::filesystem::wpath dir_path(sPathW); boost::filesystem::current_path(dir_path); }
std::vector<std::string> FileSystem::GetSubdirsInDirectory(const std::string& sDir) { std::vector<std::string> vecDirNames; std::string sPathAscii(sDir.begin(), sDir.end()); boost::filesystem::path dir_path(sDir); if ( !boost::filesystem::exists(dir_path)) { return vecDirNames; // empty vector } boost::filesystem::directory_iterator end_itr; // default construction yields past-the-end for (boost::filesystem::directory_iterator itr( dir_path ); itr != end_itr; ++itr) { std::string sDirName; if(boost::filesystem::is_directory(itr->path())) { sDirName = itr->path().filename(); vecDirNames.push_back(sDirName); } } return vecDirNames; }
static struct file_info *file_new(struct dir_info *parent, const char *name) { struct file_info *file = NULL; char *path; mode_t mode; int fd; size_t sz; CHECK(parent != NULL); path = dir_path(parent, name); mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH; fd = open(path, O_CREAT | O_EXCL | O_RDWR, mode); if (fd == -1) { CHECK(errno == ENOSPC); free(path); full = 1; return NULL; } free(path); sz = sizeof(struct file_info); file = (struct file_info *) malloc(sz); CHECK(file != NULL); memset(file, 0, sz); file->name = copy_string(name); add_dir_entry(parent, 'f', name, file); add_fd(file, fd); return file; }
static void file_unlink(struct dir_entry_info *entry) { struct file_info *file = entry->entry.file; char *path; path = dir_path(entry->parent, entry->name); /* Remove file entry from parent directory */ remove_dir_entry(entry); /* Unlink the file */ CHECK(unlink(path) != -1); free(path); /* Free struct file_info if file is not open and not linked */ if (!file->fds && !file->links) { struct write_info *w, *next; free(file->name); w = file->writes; while (w) { next = w->next; free(w); w = next; } free(file); } else if (!file->links) file->deleted = 1; }
LRESULT CALLBACK OpenDialogProc(HWND wnd_handle,UINT msg,WPARAM wparam,LPARAM lparam){ //インスタンスのポインタを取り出す FolderDialog* folder_dialog=reinterpret_cast<FolderDialog*>(::GetWindowLongPtr(wnd_handle,GWLP_USERDATA)); if(folder_dialog&& msg==WM_COMMAND&& HIWORD(wparam)==BN_CLICKED&& LOWORD(wparam)==IDOK){ if(folder_dialog){ std::vector<TCHAR> dir_path(MAX_PATHW); ::SendMessage(wnd_handle,CDM_GETFILEPATH,dir_path.size(),(LPARAM)&dir_path[0]); folder_dialog->m_dir_path.assign(&dir_path[0]); if(!folder_dialog->m_dir_path.empty()&& path::fileExists(folder_dialog->m_dir_path.c_str())){ if(path::isDirectory(folder_dialog->m_dir_path.c_str())){ ::EndDialog(wnd_handle,IDOK); }else{ folder_dialog->m_dir_path=path::getParentDirectory(folder_dialog->m_dir_path); ::EndDialog(wnd_handle,IDOK); } } } return 0; } return (folder_dialog)?::CallWindowProc(folder_dialog->m_open_proc,wnd_handle,msg,wparam,lparam):0; }
bool search_files(const std::string &str_dir_path, // in this directory, const std::string &str_ext_name, // search for this extension, std::vector<std::string> &str_file_name_list) // placing file names here if found { // clear str_file_name_list.clear(); // filter //const boost::regex filter("somefiles.*\.txt"); // current path boost::filesystem::path dir_path(str_dir_path); // for all items in the directory - files and subdirectories boost::filesystem::directory_iterator end_iter; // default construction yields past-the-end for(boost::filesystem::directory_iterator iter(dir_path); iter != end_iter; ++iter) { // skip if not a file if(!boost::filesystem::is_regular_file(iter->status())) continue; // skip if no match //boost::smatch what; //if(!boost::regex_match((*iter).path().filename(), what, filter)) continue; // if it is a file if((*iter).path().extension().string() == str_ext_name) // see below // file matches, store it str_file_name_list.push_back((*iter).path().filename().string()); } return str_file_name_list.size() > 0; }
static struct dir_info *dir_new(struct dir_info *parent, const char *name) { struct dir_info *dir; size_t sz; char *path; path = dir_path(parent, name); if (mkdir(path, 0777) == -1) { CHECK(errno == ENOSPC); full = 1; free(path); return NULL; } free(path); sz = sizeof(struct dir_info); dir = (struct dir_info *) malloc(sz); CHECK(dir != NULL); memset(dir, 0, sz); dir->name = copy_string(name); dir->parent = parent; if (parent) { struct dir_entry_info *entry; entry = dir_entry_new(); entry->type = 'd'; entry->entry.dir = dir; entry->next = parent->first; parent->first = entry; parent->number_of_entries += 1; } return dir; }
void Settings::loadLanguages() { //adding translations search paths QStringList translation_dirs; translation_dirs << QCoreApplication::applicationDirPath(); translation_dirs << QCoreApplication::applicationDirPath()+"/translations"; #ifdef PROGRAM_DATA_DIR translation_dirs << QString(PROGRAM_DATA_DIR)+"/translations"; #endif #ifdef Q_WS_MAC translation_dirs << QCoreApplication::applicationDirPath()+"/../Resources"; #endif //looking for qm-files in translation directories QStringListIterator dir_path(translation_dirs); while(dir_path.hasNext()) { QDir dir(dir_path.next()); QStringList fileNames = dir.entryList(QStringList("znotes_*.qm")); for(int i=0; i < fileNames.size(); ++i) { QString filename(fileNames[i]); QString fullpath(dir.absoluteFilePath(filename)); filename.remove(0, filename.indexOf('_') + 1); filename.chop(3); QLocale locale(filename); if(!translations[locale.language()].contains(locale.country())) { translations[locale.language()][locale.country()]=fullpath; } } } //Setting default(English) translation path if other translation not found if(!translations[QLocale::English].contains(QLocale::UnitedStates)) translations[QLocale::English][QLocale::UnitedStates]=""; }
/** @brief Search a file from a directory and its subdirectories */ bool find_file_in_subdirectories(const std::string &str_dir_path, // in this directory, const std::string &str_file_name, // search for this name, std::string &str_path_found) // placing path here if found { // current path boost::filesystem::path dir_path(str_dir_path); // check if there exists the path if(!boost::filesystem::exists(dir_path)) return false; // for all items in the directory - files and subdirectories boost::filesystem::directory_iterator end_iter; // default construction yields past-the-end for(boost::filesystem::directory_iterator iter(dir_path); iter != end_iter; ++iter) { // if it is a sub-directory if(boost::filesystem::is_directory(*iter)) { // search the file recursively if(find_file_in_subdirectories((*iter).path().string(), str_file_name, str_path_found)) return true; } // if it is a file else if((*iter).path().filename() == str_file_name) // see below { str_path_found = (*iter).path().string(); return true; } } return false; }
char *dir_search(char *fn) { char *c, *p; if(p = getenv("userdir")) if(!access(c = dir_path(fn, p), R_OK)) return c; if(p = getenv("basedir")) if(!access(c = dir_path(fn, p), R_OK)) return c; if(!access(c = dir_path(fn, "."), R_OK)) return c; return 0; }
static void file_check(struct file_info *file, int fd) { int open_and_close = 0, link_count = 0; char *path = NULL; off_t pos; struct write_info *w; struct dir_entry_info *entry; struct stat st; /* Do not check files that have errored */ if (!check_nospc_files && file->no_space_error) return; /* Do not check the same file twice */ if (file->check_run_no == check_run_no) return; file->check_run_no = check_run_no; if (fd == -1) open_and_close = 1; if (open_and_close) { /* Open file */ path = dir_path(file->links->parent, file->links->name); fd = open(path, O_RDONLY); CHECK(fd != -1); } /* Check length */ pos = lseek(fd, 0, SEEK_END); if (pos != file->length) { fprintf(stderr, "file_check failed checking length " "expected %u actual %u\n", (unsigned) file->length, (unsigned) pos); file_info_display(file); save_file(fd, file); } CHECK(pos == file->length); /* Check each write */ pos = 0; for (w = file->writes; w; w = w->next) { if (w->offset > pos) file_check_hole(file, fd, pos, w->offset - pos); file_check_data(file, fd, w); pos = w->offset + w->size; } if (file->length > pos) file_check_hole(file, fd, pos, file->length - pos); CHECK(fstat(fd, &st) != -1); CHECK(file->link_count == st.st_nlink); if (open_and_close) { CHECK(close(fd) != -1); free(path); } entry = file->links; while (entry) { link_count += 1; entry = entry->next_link; } CHECK(link_count == file->link_count); }
void Settings::loadLanguages() { //adding translations search paths QStringList translation_dirs; translation_dirs << QCoreApplication::applicationDirPath(); translation_dirs << QCoreApplication::applicationDirPath()+"/translations"; #ifdef PROGRAM_DATA_DIR translation_dirs << QString(PROGRAM_DATA_DIR)+"/translations"; #endif #ifdef Q_WS_MAC translation_dirs << QCoreApplication::applicationDirPath()+"/../Resources"; #endif #ifdef Q_OS_UNIX translation_dirs << QDir::homePath()+"/.local/share/znotes/translations"; #endif // next path for qt library translation files // For MS Windows such files generally place in the program directory. translation_dirs << QLibraryInfo::location(QLibraryInfo::TranslationsPath); //looking for qm-files in translation directories QMap<int, QMap<int, QString> > *currTranslations; QString dirSearchTemplate; for(int i = 1; i <= 2; ++i) { switch (i) { case 1: currTranslations = &translations; dirSearchTemplate = "znotes_*.qm"; break; case 2: currTranslations = &qtTranslations; dirSearchTemplate = "qt_*.qm"; break; default: ; } QStringListIterator dir_path(translation_dirs); while(dir_path.hasNext()) { QDir dir(dir_path.next()); QStringList fileNames = dir.entryList(QStringList(dirSearchTemplate)); for(int i=0; i < fileNames.size(); ++i) { QString filename(fileNames[i]); QString fullpath(dir.absoluteFilePath(filename)); filename.remove(0, filename.indexOf('_') + 1); filename.chop(3); QLocale locale(filename); if(!(*currTranslations)[locale.language()].contains(locale.country())) (*currTranslations)[locale.language()][locale.country()] = fullpath; } } //Setting default(English) translation path if other translation not found if(!(*currTranslations)[QLocale::English].contains(QLocale::UnitedStates)) (*currTranslations)[QLocale::English][QLocale::UnitedStates]=""; } }
doc_file_item_pointer doc_database::get_file(std::string path, virtual_folder_pointer pvf_from /*= get_root_vf()*/) { bfs::path dir_path(path); LDBG_ << "calling get_file(" << path << ", " << pvf_from->get_path() << ")"; doc_file_item_pointer pfi = __get_file_impl(dir_path.begin(), dir_path.end(), pvf_from); return pfi; }
static void symlink_remove(struct symlink_info *symlink) { char *path; path = dir_path(symlink->entry->parent, symlink->entry->name); remove_dir_entry(symlink->entry); CHECK(unlink(path) != -1); free(path); }
bool GetFilesInDir( const std::wstring& dir, std::vector<std::wstring>* pvec ) { boost::filesystem::path dir_path(dir); boost::filesystem::recursive_directory_iterator iter_end; pvec->clear(); for (boost::filesystem::recursive_directory_iterator iter(dir_path); iter != iter_end; ++iter) { if (boost::filesystem::is_regular_file(iter->path())) { pvec->push_back(iter->path().wstring()); } } return true; }
LLDirIterator::Impl::Impl(const std::string &dirname, const std::string &mask) : mIsValid(false) { fs::path dir_path(dirname); bool is_dir = false; // Check if path is a directory. try { is_dir = fs::is_directory(dir_path); } catch (const fs::filesystem_error& e) { LL_WARNS() << e.what() << LL_ENDL; return; } if (!is_dir) { LL_WARNS() << "Invalid path: \"" << dir_path.string() << "\"" << LL_ENDL; return; } // Initialize the directory iterator for the given path. try { mIter = fs::directory_iterator(dir_path); } catch (const fs::filesystem_error& e) { LL_WARNS() << e.what() << LL_ENDL; return; } // Convert the glob mask to a regular expression std::string exp = glob_to_regex(mask); // Initialize boost::regex with the expression converted from // the glob mask. // An exception is thrown if the expression is not valid. try { mFilterExp.assign(exp); } catch (boost::regex_error& e) { LL_WARNS() << "\"" << exp << "\" is not a valid regular expression: " << e.what() << LL_ENDL; return; } mIsValid = true; }
static struct fd_info *file_open(struct file_info *file) { int fd; char *path; path = dir_path(file->parent, file->name); fd = open(path, O_RDWR); CHECK(fd != -1); free(path); return fd_new(file, fd); }
void ForEachMSAction::AddDirectory(const std::string &name) { // get all files ending in .MS boost::filesystem::path dir_path(name); boost::filesystem::directory_iterator end_it; for(boost::filesystem::directory_iterator it(dir_path); it != end_it; ++it) { if( is_directory(it->status()) && extension(it->path()) == ".MS" ) { _filenames.push_back( it->path().string() ); } } }
static void file_truncate_file(struct file_info *file) { int fd; char *path; path = dir_path(file->links->parent, file->links->name); fd = open(path, O_WRONLY); CHECK(fd != -1); file_truncate(file, fd); CHECK(close(fd) != -1); free(path); }
static char *dir_path(struct dir_info *parent, const char *name) { char *parent_path; char *path; if (!parent) return cat_paths(tests_file_system_mount_dir, name); parent_path = dir_path(parent->parent, parent->name); path = cat_paths(parent_path, name); free(parent_path); return path; }
static struct fd_info *file_open(struct file_info *file) { int fd, flags = O_RDWR; char *path; path = dir_path(file->links->parent, file->links->name); if (tests_random_no(100) == 1) flags |= O_SYNC; fd = open(path, flags); CHECK(fd != -1); free(path); return add_fd(file, fd); }
void DirTreeView::expend_dirs( QTreeWidgetItem * item, int column ) { if (!item) return; if (item->childCount() != 0) return; QTreeWidgetItem *it=item; FileListWidgetItem *fi = dynamic_cast<FileListWidgetItem*>(it); QString dir_path(fi->get_real_str() ); while (fi->parent()) { fi=dynamic_cast<FileListWidgetItem*>(fi->parent() ); QString tmp_str=dir_path; dir_path= fi->get_real_str() + QDIR_SEPARATOR + tmp_str; } QDir dir(dir_path); //dir.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks | QDir::AllDirs); dir.setFilter(QDir::AllDirs | QDir::Hidden); QFileInfoList file_info_list = dir.entryInfoList(); for (int i = 0; i < file_info_list.size(); ++i) { QFileInfo file_info = file_info_list.at(i); #ifdef DIR_NAME_DEG qDebug("file_info.fileName() : %s", file_info.fileName().toAscii().data() ); qDebug("file_info.isDir() : %d", file_info.isDir() ); #endif if (file_info.isDir() ) { if ( file_info.fileName() =="." || file_info.fileName()=="..") continue; fi = new FileListWidgetItem (item); fi->set_real_str(file_info.fileName() ); #if 1 QTextCodec *tc; tc = QTextCodec::codecForName(get_cur_enc_str() ); QString fn(tc->toUnicode(file_info.fileName().toAscii() ) ); fi->setText(0, fn); #else qDebug("get_cur_enc_str() : %s", get_cur_enc_str() ); fi->setText(0, file_info.fileName() ); #endif } } }