Esempio n. 1
0
RecordingSet::~RecordingSet()
{
  clearTemp();
  //try to remove temp directory; This will of course fail if there are files in there
  //so it will only clean the directory if it is not needed anymore;
  QDir().rmdir(getBaseDirectory());
}
Esempio n. 2
0
    bool FileManager::save(Image & image, const std::string & path, bool createSymbol)
    {
        // -------------------------
        // Create filename and directories if not exist
        
        unsigned long found = path.find("/");
        while(found != -1)
        {
            std::string subDirectory = path.substr(0, found);
            createDirectoryIfNotExists(subDirectory);
            found = path.find("/",found+1);
        }
        // -------------------------
        // Call save method on image
        
        std::string pathToImage = getBaseDirectory() + "/" + path;
        if(image.save(pathToImage))
        {
            if(createSymbol)
            {
                std::string link = SYMBOL_DIRECTORY + path;
                symlink(pathToImage.c_str(), link.c_str());
            }

            return true;
        }
        else
        {
            return false;
        }
            
    }
Esempio n. 3
0
// Finds files recursively
// Committed is if the current recursive path only contains files to be deleted (and thus simply list all files found)
// Otherwise wildcards are examined and directories are recursed
static void FindFiles(TCHAR *path, BOOL committed, BOOL oneVolumeOnly) {
	WIN32_FIND_DATA ffd;
	BY_HANDLE_FILE_INFORMATION info;
	TCHAR full[BIG_PATH+5];
	HANDLE hFind;
	DWORD dwError, attrib;
	TCHAR *file, *base;
	BOOL match_all;
	set *matches = NULL;

	DWORD len = _tcslen(path);
	while (len > 0 && path[len-1] == L'\\')
		path[--len] = 0;
	file = copyStr(path);
	attrib = GetFileAttributes(path);
	match_all = attrib != INVALID_FILE_ATTRIBUTES && ((attrib & FILE_ATTRIBUTE_DIRECTORY) != 0);
	if (match_all) {
		committed = TRUE;
		file[len  ] = TEXT('\\');
		file[len+1] = TEXT('*');
		file[len+2] = 0;
	} else {
		file[len] = 0;
	}
	
	base = getBaseDirectory(file);
	if (!committed)
		matches = set_create((compare_func)&_tcscmp);

	// first pass we match the pattern only and everything we find is committed
	hFind = FindFirstFileEx(file, FindExInfoBasic, &ffd, FindExSearchNameMatch, NULL, FIND_FIRST_EX_LARGE_FETCH);
	if (hFind == INVALID_HANDLE_VALUE) {
		dwError = GetLastError();
		if (dwError != ERROR_FILE_NOT_FOUND && dwError != ERROR_ACCESS_DENIED)
			LogFileError(TEXT("FindFirstFileEx in FindFiles failed for"), file, dwError);
	} else {
		do {
			if (_tcscmp(ffd.cFileName, TEXT("..")) == 0 || _tcscmp(ffd.cFileName, TEXT(".")) == 0)
				continue;
			makeFullPath(base, ffd.cFileName, full);
			vector_append(files, copyStr(full));
			if ((ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && !(oneVolumeOnly && (ffd.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) && FileChangesVolume(full))) {
				if (!committed)
					set_insert(matches, copyStr(ffd.cFileName));
				FindFiles(full, TRUE, oneVolumeOnly);
			}
		} while (FindNextFile(hFind, &ffd) != 0);
		dwError = GetLastError();
		if (dwError != ERROR_NO_MORE_FILES)
			LogError(TEXT("FindNextFile in FindFiles"), dwError);
		FindClose(hFind);
	}

	if (!committed) {
		// second pass we are just looking for directories to recurse into
		// if we are already committed then there is no need to do this as all directories and files will be enumerated above

		TCHAR *pattern = getFileName(file);
		TCHAR *baseSrch = copyStr(base);
		len = _tcslen(base);
		baseSrch[len ] = L'\\';
		baseSrch[len+1] = L'*';
		baseSrch[len+2] = 0;

		hFind = FindFirstFileEx(baseSrch, FindExInfoBasic, &ffd, FindExSearchLimitToDirectories, NULL, FIND_FIRST_EX_LARGE_FETCH);
		if (hFind == INVALID_HANDLE_VALUE) {
			dwError = GetLastError();
			if (dwError != ERROR_FILE_NOT_FOUND && dwError != ERROR_ACCESS_DENIED)
				LogFileError(TEXT("FindFirstFileEx in FindFiles2 failed for"), baseSrch, dwError);
		} else {
			do {
				if (_tcscmp(ffd.cFileName, TEXT("..")) != 0 && _tcscmp(ffd.cFileName, TEXT(".")) != 0 && ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
					if (!set_contains(matches, ffd.cFileName)) { // don't re-recurse into a directory
						makeFullPath2(base, ffd.cFileName, pattern, full);
						if (!(oneVolumeOnly && (ffd.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) && FileChangesVolume(full))) {
							FindFiles(full, FALSE, oneVolumeOnly);
						}
					}
				}
			} while (FindNextFile(hFind, &ffd) != 0);
			dwError = GetLastError();
			if (dwError != ERROR_NO_MORE_FILES)
				LogError(TEXT("FindNextFile in FindFiles2"), dwError);
			FindClose(hFind);
		}
		free(baseSrch);
	}

	free(file);
	free(base);
	if (!committed)
		set_destroy(matches, TRUE);
}