static int
_invalidateCache(const char *path) {
    int status;
    char cachePath[MAX_NAME_LEN];
    char cacheWorkPath[MAX_NAME_LEN];

    if (path == NULL) {
        rodsLog (LOG_ERROR, "_invalidateCache: input path is NULL");
        return (SYS_INTERNAL_NULL_INPUT_ERR);
    }

    if ((status = _getCacheWorkPath(path, cacheWorkPath)) < 0) {
        return status;
    }

    if ((status = _getCachePath(path, cachePath)) < 0) {
        return status;
    }

    if (isDirectory(cachePath) == 0) {
        // directory
        status = removeDirRecursive(cachePath);
    } else {
        // file
        // remove incomplete preload cache if exists
        unlink(cacheWorkPath);
        status = unlink(cachePath);
    }

    return status;
}
Example #2
0
void removeSaveDir(int slot) {
	// game slots are currently 1-4
	if (slot == 0) return;

	std::stringstream ss;
	ss << PATH_USER << "saves/" << SAVE_PREFIX << "/" << slot;

	if (isDirectory(path(&ss))) {
		removeDirRecursive(path(&ss));
	}
}
int
removeDirRecursive(const char *path) {
    DIR *dir = opendir(path);
    char filepath[MAX_NAME_LEN];
    struct dirent *entry;
    struct stat statbuf;
    int status;
    int statusFailed = 0;

    if (dir != NULL) {
        while ((entry = readdir(dir)) != NULL) {
            if (!strcmp(entry->d_name, ".") || !strcmp(entry->d_name, "..")) {
                continue;
            }

            snprintf(filepath, MAX_NAME_LEN, "%s/%s", path, entry->d_name);
            rodsLog (LOG_DEBUG, "removeDirRecursive: removing : %s", dir);

            if (!stat(filepath, &statbuf)) {
                // has entry
                if (S_ISDIR(statbuf.st_mode)) {
                    // directory
                    status = removeDirRecursive(filepath);
                    if(status < 0) {
                        statusFailed = status;
                    }
                } else {
                    // file
                    status = unlink(filepath);
                    if(status < 0) {
                        statusFailed = status;
                    }
                }
            }
        }
        closedir(dir);
    }

    if(statusFailed == 0) {
        statusFailed = rmdir(path);
    }

    return statusFailed;
}