set<string> DirectoryMonitor::Server::restoreFailedPaths() { set<string> failedDirectoriesCopy, restoredDirectories; { RLock l(cs); failedDirectoriesCopy = failedDirectories; } for (const auto& dir : failedDirectoriesCopy) { try { addDirectory(dir); restoredDirectories.insert(dir); } catch (...) { //... } } if (!restoredDirectories.empty()) { WLock l(cs); for (const auto& dir : restoredDirectories){ failedDirectories.erase(dir); } } return restoredDirectories; }
void FileList::addDirectory(const QString &directory, bool recursive) { QDir dir(directory); dir.setSorting(QDir::Name); const QStringList filters = FileList::getDefaultFilters(); const QStringList origNameFilters = dir.nameFilters(); dir.setNameFilters(filters); if (!recursive) { dir.setFilter(QDir::Files | QDir::NoDotAndDotDot); QFileInfoList items = dir.entryInfoList(); mFileList += items; } else { dir.setFilter(QDir::Files | QDir::NoDotAndDotDot); QFileInfoList items = dir.entryInfoList(); mFileList += items; dir.setNameFilters(origNameFilters); dir.setFilter(QDir::Dirs | QDir::NoDotAndDotDot); QFileInfoList list = dir.entryInfoList(); QFileInfo item; foreach (item, list) { const QString path = item.canonicalFilePath(); addDirectory(path, recursive); } } }
QStringList BBActionAdd::addDirectory(const QString& dirname) { BBDEBUG << dirname; QFileInfo info(dirname); if (!info.exists()) { return QStringList(); } QStringList list; if (dirname != BBSettings::instance()->directory() && checkExtension(info)) list << dirname; if (info.isDir()) { QDir dir(dirname); BBSvn::removeDir(dir); QFileInfoList files = dir.entryInfoList(QDir::AllEntries | QDir::Hidden | QDir::NoSymLinks); foreach (QFileInfo file, files) { if (file.fileName().startsWith(".")) continue; list << addDirectory(file.absoluteFilePath()); } }
void BBActionAdd::run() { BBDEBUG; m_files = addDirectory(m_dirname); runAdd(); }
bool FileList::addDirectory(const UString &base, const boost::filesystem::path &directory, int recurseDepth) { if (!exists(directory) || !is_directory(directory)) // Path is either no directory or doesn't exist return false; try { // Iterator over the directory's contents directory_iterator itEnd; for (directory_iterator itDir(directory); itDir != itEnd; ++itDir) { if (is_directory(itDir->status())) { // It's a directory. Recurse into it if the depth limit wasn't yet reached if (recurseDepth != 0) if (!addDirectory(base, itDir->path(), (recurseDepth == -1) ? -1 : (recurseDepth - 1))) return false; } else // It's a path, add it to the list addPath(base, itDir->path()); } } catch (...) { return false; } return true; }
void MainWindow::connectSignals ( void ) { connect( ui->fileMenu, SIGNAL( aboutToShow() ), this, SLOT( enableExport() ) ); connect( ui->toolsMenu, SIGNAL( aboutToShow() ), this, SLOT( enableClassify() ) ); connect( ui->addFilesAction, SIGNAL( triggered() ), this, SLOT( addFiles() ) ); connect( ui->addDirectoryAction, SIGNAL( triggered() ), this, SLOT( addDirectory() ) ); connect( ui->aetExportAction, SIGNAL( triggered() ), this, SLOT( exportAetSession() ) ); connect( ui->stepExportAction, SIGNAL( triggered() ), this, SLOT( exportStepSession() ) ); connect( ui->exitAction, SIGNAL( triggered() ), qApp, SLOT( quit() ) ); connect( ui->classifyAction, SIGNAL( triggered() ), session, SLOT( classify() ) ); connect( ui->optionsAction, SIGNAL( triggered() ), this, SLOT( showOptionsDialog() ) ); connect( this, SIGNAL( settingsChanged() ), session, SLOT( loadSettings() ) ); connect( itemListModel, SIGNAL( dataChanged( QModelIndex, QModelIndex ) ), this, SLOT( updateFileTreeView() ) ); connect( variantListModel, SIGNAL( dataChanged( QModelIndex, QModelIndex ) ), this, SLOT( updateFileTreeView() ) ); connect( ui->varianceSlider, SIGNAL( valueChanged( int ) ), session, SLOT( setCurrentVariance( int ) ) ); connect( session, SIGNAL( classificationChanged() ), this, SLOT( updateVariance() ) ); }
LRESULT FavoriteDirsPage::onClickedAdd(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) { tstring target; if(WinUtil::browseDirectory(target, m_hWnd)) { addDirectory(target); } return 0; }
void GofunWidget::popupCAActivated(int id) { switch(id) { case PID_Add_Directory: addDirectory(); break; } }
void FileList::addPathList(const QStringList &paths) { QString path; foreach (path, paths) { QFileInfo inf(path); if (inf.isFile()) addFile(path); else addDirectory(path, true); }
CAddFilesDialog::CAddFilesDialog(QWidget *parent) : QDialog(parent), ui(new Ui::CAddFilesDialog) { ui->setupUi(this); ui->tableView->setModel(&m_model); connect(ui->addBtn, SIGNAL(clicked()), this, SLOT(onAddFile())); connect(ui->actionAdd_directory, SIGNAL(triggered()), this, SLOT(addDirectory())); connect(ui->actionAdd_file, SIGNAL(triggered()), this, SLOT(addFiles())); }
FileWatcher::FileWatcher(QString dir, ScanType type, qint32 notebookLid, bool subdirs, QObject *parent) : QFileSystemWatcher(parent) { this->notebookLid = notebookLid; this->dir = dir; this->scanType = type; this->includeSubdirectories = subdirs; addDirectory(dir); connect(this, SIGNAL(directoryChanged(QString)), this, SLOT(saveDirectory(QString))); connect(this, SIGNAL(fileChanged(QString)), this, SLOT(saveFile(QString))); }
void Settings::setupGui() { ui.setupUi(this); connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(saveSettings())); connect(ui.patternEdit, SIGNAL(textChanged(QString)), this, SLOT(changeAddPatternButtonState(QString))); connect(ui.patternAddButton, SIGNAL(clicked()), this, SLOT(addPattern())); connect(ui.patternDeleteButton, SIGNAL(clicked()), this, SLOT(deletePattern())); connect(ui.directoryOpenButton, SIGNAL(clicked()), this, SLOT(addDirectory())); connect(ui.directoryDeleteButton, SIGNAL(clicked()), this, SLOT(deleteDirectory())); }
void SearchManager::clear() { SearchSet::clear(); // Always keep system specific archives in the SearchManager. // But we give them a lower priority than the default priority (which is 0), // so that archives added by client code are searched first. if (g_system) g_system->addSysArchivesToSearchSet(*this, -1); // Add the current dir as a very last resort. // See also bug #2137680. addDirectory(".", ".", -2); }
LRESULT SharePage::onClickedAdd(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) { tstring target; if (WinUtil::browseDirectory(target, m_hWnd)) { addDirectory(target); if (!HashProgressDlg::g_is_execute) // fix http://code.google.com/p/flylinkdc/issues/detail?id=1126 { HashProgressDlg(true).DoModal(); } } return 0; }
void SearchSet::addSubDirectoriesMatching(const FSNode &directory, String origPattern, bool ignoreCase, int priority) { FSList subDirs; if (!directory.getChildren(subDirs)) return; String nextPattern, pattern; String::const_iterator sep = Common::find(origPattern.begin(), origPattern.end(), '/'); if (sep != origPattern.end()) { pattern = String(origPattern.begin(), sep); ++sep; if (sep != origPattern.end()) nextPattern = String(sep, origPattern.end()); } else { pattern = origPattern; } // TODO: The code we have for displaying all matches, which vary only in case, might // be a bit overhead, but as long as we want to display all useful information to the // user we will need to keep track of all directory names added so far. We might // want to reconsider this though. typedef HashMap<String, bool, IgnoreCase_Hash, IgnoreCase_EqualTo> MatchList; MatchList multipleMatches; MatchList::iterator matchIter; for (FSList::const_iterator i = subDirs.begin(); i != subDirs.end(); ++i) { String name = i->getName(); if (Common::matchString(name.c_str(), pattern.c_str(), ignoreCase)) { matchIter = multipleMatches.find(name); if (matchIter == multipleMatches.end()) { multipleMatches[name] = true; } else { if (matchIter->_value) { warning("Clash in case for match of pattern \"%s\" found in directory \"%s\": \"%s\"", pattern.c_str(), directory.getPath().c_str(), matchIter->_key.c_str()); matchIter->_value = false; } warning("Clash in case for match of pattern \"%s\" found in directory \"%s\": \"%s\"", pattern.c_str(), directory.getPath().c_str(), name.c_str()); } if (nextPattern.empty()) addDirectory(name, *i, priority); else addSubDirectoriesMatching(*i, nextPattern, ignoreCase, priority); } } }
bool KviPackageWriter::addDirectory(const QString & szLocalDirectoryName, const QString & szTargetDirectoryPrefix, kvi_u32_t uAddFileFlags) { QDir d(szLocalDirectoryName); QDir::Filters iFlags; iFlags = QDir::Files | QDir::Readable; if(!(uAddFileFlags & FollowSymLinks)) iFlags |= QDir::NoSymLinks; int j; QFileInfoList sl = d.entryInfoList(iFlags); for(j = 0; j < sl.size(); j++) { QString szSFileName = szLocalDirectoryName; KviQString::ensureLastCharIs(szSFileName, QChar(KVI_PATH_SEPARATOR_CHAR)); QFileInfo slowCopy = sl.at(j); szSFileName += slowCopy.fileName(); QString szDFileName = szTargetDirectoryPrefix; KviQString::ensureLastCharIs(szDFileName, QChar(KVI_PATH_SEPARATOR_CHAR)); szDFileName += slowCopy.fileName(); if(!addFileInternal(&slowCopy, szSFileName, szDFileName, uAddFileFlags)) return false; } iFlags = QDir::Dirs | QDir::Readable; if(!(uAddFileFlags & FollowSymLinks)) iFlags |= QDir::NoSymLinks; sl = d.entryInfoList(iFlags); for(j = 0; j < sl.size(); j++) { QString szDir = sl.at(j).fileName(); if(!KviQString::equalCS(szDir, "..") && !KviQString::equalCS(szDir, ".")) { QString szSDirName = szLocalDirectoryName; KviQString::ensureLastCharIs(szSDirName, QChar(KVI_PATH_SEPARATOR_CHAR)); szSDirName += szDir; QString szDDirName = szTargetDirectoryPrefix; KviQString::ensureLastCharIs(szDDirName, QChar(KVI_PATH_SEPARATOR_CHAR)); szDDirName += szDir; if(!addDirectory(szSDirName, szDDirName, uAddFileFlags)) return false; } } return true; }
LRESULT LocationsPage::onClickedAdd(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) { BrowseDlg browseDlg(m_hWnd, BrowseDlg::TYPE_SETTINGS_RESOURCES, BrowseDlg::DIALOG_SELECT_FOLDER); tstring path; if (!browseDlg.show(path)) { return 0; } LineDlg dlg; dlg.allowEmpty = false; dlg.title = TSTRING(VIRTUAL_NAME); dlg.description = path; dlg.line = Util::getLastDir(path); if (dlg.DoModal() == IDOK) { addDirectory(Text::fromT(path), Text::fromT(dlg.line)); } return 0; }
LRESULT FavoriteDirsPage::onDropFiles(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& /*bHandled*/){ HDROP drop = (HDROP)wParam; tstring buf; buf.resize(MAX_PATH); UINT nrFiles; nrFiles = DragQueryFile(drop, (UINT)-1, NULL, 0); for(UINT i = 0; i < nrFiles; ++i){ if(DragQueryFile(drop, i, &buf[0], MAX_PATH)){ if(PathIsDirectory(&buf[0])) addDirectory(buf); } } DragFinish(drop); return 0; }
void MdsEditView::refresh() { CSSM_NAME_LIST_PTR pDirNameList = NULL; CSSM_RETURN ret = g_doc->m_pMds->GetDbNames(&pDirNameList); m_treeView->clear(); QListViewItem * item = new QListViewItem( m_treeView, 0 ); item->setText( 0, "MDS"); item->setPixmap( 0, uic_load_pixmap( "root.png" ) ); if ( ret == CSSM_OK ) { for ( uint32 i = 0; i < pDirNameList->NumStrings; i++ ) { addDirectory( (g_doc->m_pMds), pDirNameList->String[i], item ); } } }
LRESULT SharePage::onDropFiles(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& /*bHandled*/) { HDROP drop = (HDROP)wParam; AutoArray <TCHAR> buf(FULL_MAX_PATH); UINT nrFiles; nrFiles = DragQueryFile(drop, (UINT) - 1, NULL, 0); for (UINT i = 0; i < nrFiles; ++i) { // TODO добавить поддержку длинных путей if (DragQueryFile(drop, i, buf, FULL_MAX_PATH)) { if (PathIsDirectory(buf)) addDirectory(buf.data()); } } DragFinish(drop); return 0; }
int MyCreat(int pinum, int type, char *name){ //Variables int len, rc; //Check for invalid inum if(inodes[pinum] == NULL) return -1; //Check to see if the name is too long len = strlen(name); if(len > 28) return -1; //Check to see if name already exists //INSERT CHECK HERE //Create the directory or file if(type == MFS_DIRECTORY) rc = addDirectory(pinum, name); else rc = createFile(pinum, name); return rc; }
void StereoCalibrationDialog::createCalibDirs() { addDirectory(calibDir + "Left/"); addDirectory(calibDir + "Right/"); }
void FavoriteDirsPage::handleAddClicked() { tstring target; if(createFolderDialog().open(target)) { addDirectory(target); } }
void FavoriteDirsPage::handleDragDrop(const TStringList& files) { for(TStringIterC i = files.begin(); i != files.end(); ++i) if(PathIsDirectory(i->c_str())) addDirectory(*i); }
/* write the platform-dependent iteration through a directory. Basic Algorithm: For each element in the directory if the element is a directory (and recurse is non-zero) recursively call addDirectory if the element is a file stat the file and allocate a new NESHARE_FILE_OBJ encode the filename and fill in the OBJ */ int neFileManager::addDirectory(char *directory, int recurse) { int ret = 1; int count = 0; /* get the base path directory (and format properly) */ std::string basePath = formatBasePath(directory); struct dirent *dentry = NULL; DIR *dir = opendir(basePath.c_str()); if (dir) { while((dentry = readdir(dir))) { if (dentry->d_name[0] == '.') { continue; } /* stat the file to get the file size and distinguish b/w a dir and regular file */ struct stat statbuf; memset(&statbuf,0,sizeof(statbuf)); std::string direntry = basePath + std::string(dentry->d_name); if (stat((char *)direntry.c_str(),&statbuf)) { continue; } /* handle directory entry */ if (S_ISDIR(statbuf.st_mode)) { if (recurse) { /* adjust the basePath and recurse */ std::string newBasePath = basePath + std::string(dentry->d_name); ret = addDirectory((char *)newBasePath.c_str(), recurse); } /* count directories as files as well */ count++; } else /* handle file entry */ { /* format the filename */ std::string filename = getEncoded( (char *)basePath.c_str(),dentry->d_name); /* create a new file entry to map */ NESHARE_FILE_OBJ *newFileObj = new NESHARE_FILE_OBJ(); if ((basePath.length() + strlen(dentry->d_name)) < NEFILE_MAX_NAME_LEN) { newFileObj->fileSize = (unsigned long)statbuf.st_size; strcpy(newFileObj->realFilename,basePath.c_str()); strcat(newFileObj->realFilename,dentry->d_name); strcpy(newFileObj->encodedFilename,filename.c_str()); /* finally, insert the file into the map */ m_encodedFilenames[filename] = newFileObj; count++; } else { iprintf("Filename too long. Skipping %s\n", dentry->d_name); delete newFileObj; continue; } } } closedir(dir); ret = (((count > 0) || (ret == 0)) ? 0 : 1); } return ret; }
/** * @brief Store additional directories. * * @param directories List of directories. * * @see addDirectory */ void addDirectories(DynamicArray<FilePath> directories) { for (auto&& directory : directories) addDirectory(std::move(directory)); }
int main(int argc, char *argv[]){ //Variables int sd, fd, rc, returnCode, i, size; struct sockaddr_in s; int problem = sizeof(MFS_Dir_t) + sizeof(MFS_Inode_t) + sizeof(MFS_InodeMap_t) + (2 * sizeof(MFS_DirEnt_t)); //Initialize the client and server messages client = (ClientMessage_t *)malloc(sizeof(ClientMessage_t)); server = (ServerMessage_t *)malloc(sizeof(ServerMessage_t)); //Check for file image /* if(argc == 3){ sd = UDP_Open(atoi(argv[1])); fd = open(argv[2], O_RDWR); assert(sd > -1); assert(fd > -1); } */ if(argc == 3){ printf("Check: %d\n", atoi(argv[1])); //Open the socket and the image sd = UDP_Open(atoi(argv[1])); //sd = UDP_Open(29344); fd = open(argv[2], O_RDWR | O_CREAT | O_TRUNC, S_IRWXU); assert(sd > -1); assert(fd > -1); //Create image imageSize = sizeof(MFS_Checkpoint_t) + (256 * sizeof(MFS_InodeMap_t)) + (4096 * sizeof(MFS_Inode_t)) + (14 * 4096 * 4096); image = malloc(imageSize); if(image == NULL) printf("MALLOC PROBLEM\n"); size = 0; //Create and initialize the checkpoint temp = image; position = image; end = image; checkpoint = (MFS_Checkpoint_t *)temp; position += sizeof(MFS_Checkpoint_t); //Initialize the arrays for(i = 0; i < 256; i++) inodeMap[i] = NULL; for(i = 0; i < 4096; i++) inodes[i] = NULL; //Create the root directory rc = addDirectory(0, "/"); } else{ printf("Usage: server portnum [file-system-image]\n"); exit(-1); } //Start server loop while(1){ //Check to make sure size is okay //Get the message from the Client rc = UDP_Read(sd, &s, (char *)client, sizeof(ClientMessage_t)); //Perform the correct operation if(rc > 0){ if(client->syscallNumber == LOOKUP){ //Lookup the file returnCode = MyLookup(client->inum, client->buffer); printf("RETURNCODE: %d\n", returnCode); //Setup the return message server->returnCode = returnCode; printf("server server return: %d\n", server->returnCode); rc = UDP_Write(sd, &s, (char *)server, sizeof(ServerMessage_t)); } else if(client->syscallNumber == STAT){ //Get the Stat info about the specific inum returnCode = MyStat(client->inum); //Setup the return message server->returnCode = returnCode; rc = UDP_Write(sd, &s, (char *)server, sizeof(ServerMessage_t)); } else if(client->syscallNumber == WRITE){ printf("ENTERED WRITE 1\n"); printf("here here here: %d\n", client->inum); //Update image returnCode = MyWrite(client->inum, client->buffer, client->block); //Update checkpoint checkpoint->end = end - image; //Write to disk rc = write(fd, image, imageSize); if(rc <= 0) exit(-1); fsync(fd); //Setup the return message server->returnCode = returnCode; rc = UDP_Write(sd, &s, (char *)server, sizeof(ServerMessage_t)); } else if(client->syscallNumber == READ){ //Read the specified block of data returnCode = MyRead(client->inum, client->block); printf("server server server buffer: %s\n", server->buffer); //Setup the return message server->returnCode = returnCode; rc = UDP_Write(sd, &s, (char *)server, sizeof(ServerMessage_t)); } else if(client->syscallNumber == CREAT){ //Update image returnCode = MyCreat(client->inum, client->type, client->buffer); //Update checkpoint checkpoint->end = end - image; //Write to disk rc = write(fd, image, imageSize); if(rc <= 0) exit(-1); fsync(fd); //Setup the return message server->returnCode = returnCode; rc = UDP_Write(sd, &s, (char *)server, sizeof(ServerMessage_t)); } else if(client->syscallNumber == UNLINK){ //Unlink and update message returnCode = MyUnlink(client->inum, client->buffer); //Update checkpoint checkpoint->end = end - image; //Write to disk rc = write(fd, image, imageSize); if(rc <= 0) exit(-1); fsync(fd); //Setup the return message server->returnCode = returnCode; rc = UDP_Write(sd, &s, (char *)server, sizeof(ServerMessage_t)); } else{ //Update checkpoint checkpoint->end = end - image; //This is the case for shutdown rc = write(fd, image, imageSize); if(rc <= 0) exit(-1); fsync(fd); //Set up the return message server->returnCode = 0; rc = UDP_Write(sd, &s, (char *)server, sizeof(ServerMessage_t)); exit(0); } } } return 0; }
/* * Fill the fileWidget box with the contents of the current directory */ void restorePage::fillDirectory() { mainWin->waitEnter(); char modes[20], user[20], group[20], size[20], date[30]; char marked[10]; int pnl, fnl; POOLMEM *file = get_pool_memory(PM_FNAME); POOLMEM *path = get_pool_memory(PM_FNAME); fileWidget->clear(); m_console->write_dir(m_conn, "dir", false); QList<QTreeWidgetItem *> treeItemList; QStringList item; m_rx.setPattern("has no children\\.$"); bool first = true; while (m_console->read(m_conn) > 0) { char *p = m_console->msg(m_conn); char *l; strip_trailing_newline(p); if (*p == '$' || !*p) { continue; } if (first) { if (m_rx.indexIn(QString(p)) != -1) { continue; } first = false; } l = p; skip_nonspaces(&p); /* permissions */ *p++ = 0; bstrncpy(modes, l, sizeof(modes)); skip_spaces(&p); skip_nonspaces(&p); /* link count */ *p++ = 0; skip_spaces(&p); l = p; skip_nonspaces(&p); /* user */ *p++ = 0; skip_spaces(&p); bstrncpy(user, l, sizeof(user)); l = p; skip_nonspaces(&p); /* group */ *p++ = 0; bstrncpy(group, l, sizeof(group)); skip_spaces(&p); l = p; skip_nonspaces(&p); /* size */ *p++ = 0; bstrncpy(size, l, sizeof(size)); skip_spaces(&p); l = p; skip_nonspaces(&p); /* date/time */ skip_spaces(&p); skip_nonspaces(&p); *p++ = 0; bstrncpy(date, l, sizeof(date)); skip_spaces(&p); if (*p == '*') { bstrncpy(marked, "*", sizeof(marked)); p++; } else { bstrncpy(marked, " ", sizeof(marked)); } split_path_and_filename(p, path, &pnl, file, &fnl); item.clear(); item << "" << file << modes << user << group << size << date; if (item[1].endsWith("/")) { addDirectory(item[1]); } QTreeWidgetItem *ti = new QTreeWidgetItem((QTreeWidget *)0, item); ti->setTextAlignment(5, Qt::AlignRight); /* right align size */ if (strcmp(marked, "*") == 0) { ti->setIcon(0, QIcon(QString::fromUtf8(":images/check.png"))); ti->setData(0, Qt::UserRole, true); } else { ti->setIcon(0, QIcon(QString::fromUtf8(":images/unchecked.png"))); ti->setData(0, Qt::UserRole, false); } treeItemList.append(ti); } fileWidget->clear(); fileWidget->insertTopLevelItems(0, treeItemList); for (int i=0; i<7; i++) { fileWidget->resizeColumnToContents(i); } free_pool_memory(file); free_pool_memory(path); mainWin->waitExit(); }
FileList::FileList(const UString &directory, int recurseDepth) { addDirectory(directory, recurseDepth); }
void ManageLibraryDialog::slotAddDirectory() { QString dirToAdd = QFileDialog::getExistingDirectory(this, "Add Directory to Library", "/"); if (dirToAdd.length() > 0) { emit addDirectory(dirToAdd); } }