Exemple #1
0
/**
 * The recursive helper function. It deletes all files inside specified
 * directory and calls itself to delete subdirectories.
 *
 * @param pDirName the directory to delete
 * @param pSep system-dependent file separator
 */
void do_cleanup(const pcsl_string* pDirName, const pcsl_string* pSep)
{
    void* fileList = NULL;
    pcsl_string fileName = PCSL_STRING_NULL;
    pcsl_string dirName  = PCSL_STRING_NULL;

    // add tailing file separator to directory name
    if (pcsl_string_cat(pDirName, pSep, &dirName) != PCSL_STRING_OK) {
        return;
    }

    fileList = pcsl_file_openfilelist(&dirName);
    if (fileList == NULL) {
        pcsl_string_free(&dirName);
        return;
    }

    // iterate over the directory's content
    while (!pcsl_file_getnextentry(fileList, &dirName, &fileName)) {
        int isDir = pcsl_file_is_directory(&fileName);
        if (isDir == 1) {
            // make recursion
            do_cleanup(&fileName, pSep);
        } else {
            // remove file
            pcsl_file_unlink(&fileName);
        }
        pcsl_string_free(&fileName);
    };

    pcsl_string_free(&dirName);
    pcsl_file_closefilelist(fileList);
    // remove empty directory
    pcsl_file_rmdir(pDirName);
}
Exemple #2
0
/**
 * The getUsedSpace function checks the size of used space in storage. 
 */
long pcsl_file_getusedspace(const pcsl_string * systemDir)
{
    long used = 0;
    void* pIterator;
    pcsl_string current = PCSL_STRING_NULL;
    struct _stat stat_buf;

    pIterator = pcsl_file_openfilelist(systemDir);
    for (; ; ) {
	if (pcsl_file_getnextentry(pIterator, systemDir, &current) == -1) {
            break;
	}

	{
          const jchar * pwszFilename = pcsl_string_get_utf16_data(&current);

	  if (NULL == pwszFilename) {
            break;
	  }

	  /* Don't count the subdirectories "." and ".." */
	  if (_wstat(pwszFilename, &stat_buf) != -1 &&
	      !S_ISDIR(stat_buf.st_mode)) {
            used += stat_buf.st_size;
	  }

          pcsl_string_release_utf16_data(pwszFilename, &current);
	}

	pcsl_string_free(&current);
    }

    pcsl_file_closefilelist(pIterator);
    return used;
}
Exemple #3
0
/**
 * The getUsedSpace function checks the size of used space in storage. 
 */
long pcsl_file_getusedspace(const pcsl_string * systemDir)
{
    long used = 0;
    void* pIterator;
    pcsl_string current = PCSL_STRING_NULL;

    pIterator = pcsl_file_openfilelist(systemDir);
    for (; ; ) {
        if (pcsl_file_getnextentry(pIterator, systemDir, &current) == -1) {
            break;
        }

        {
            long size = pcsl_file_sizeof(&current);
            if (size >= 0)
                used += size;
        }

        pcsl_string_free(&current);
    }

    pcsl_file_closefilelist(pIterator);
    return used;
}
Exemple #4
0
/*
 * Close the handle properly
 * and deallocate the memory
 *
 */
void
storageCloseFileIterator(void* handle)
{
    pcsl_file_closefilelist(handle);
}