This commit is contained in:
David Humphrey (:humph) david.humphrey@senecacollege.ca 2015-10-23 16:21:06 -04:00
Родитель 1c40c5ab76
Коммит a289206515
2 изменённых файлов: 36 добавлений и 22 удалений

Просмотреть файл

@ -28,11 +28,7 @@ define(function (require, exports, module) {
paths[url] = filename;
}
// Remove the cached BLOB URL for the given filename
function remove(filename) {
filename = decodePath(filename);
filename = Path.normalize(filename);
function _remove(filename) {
var url = blobURLs[filename];
// The first time a file is written, we won't have
// a stale cache entry to clean up.
@ -46,6 +42,26 @@ define(function (require, exports, module) {
URL.revokeObjectURL(url);
}
// Remove the cached BLOB URL for the given file path, or files beneath
// this path if it is a dir. Returns all file paths that were removed.
function remove(path) {
path = decodePath(path);
path = Path.normalize(path);
var removed = [];
// If this is a dir path, look for other paths entries below it
Object.keys(blobURLs).forEach(function(key) {
// If this filename matches exactly, or is a root path (i.e., other
// filenames begin with "<path>/...", remove it. Otherwise just skip.
if(key === path || key.indexOf(path + "/") === 0) {
removed.push(key);
_remove(key);
}
});
return removed;
}
// Update the cached records for the given filename
function rename(oldPath, newPath) {
oldPath = decodePath(oldPath);

Просмотреть файл

@ -347,35 +347,33 @@ define(function (require, exports, module) {
});
}
function unlink(path, callback) {
path = decodePath(path);
fs.stat(path, function(err, stats) {
function _rmfr(path, callback) {
// Regardless of whether we're passed a file or dir path, recursively delete it all.
fs.rm(path, {recursive: true}, function(err) {
if (err) {
callback(_mapError(err));
return;
}
// Deal with dir vs. file
var fnName = stats.type === "DIRECTORY" ? 'rmdir' : 'unlink';
fs[fnName](path, function(err) {
// TODO: deal with the symlink case (i.e., only remove cache
// item if file is really going away).
BlobUtils.remove(path);
if(!err) {
BrambleEvents.triggerFileRemoved(path);
}
callback(_mapError(err));
// TODO: deal with the symlink case (i.e., only remove cache
// item if file is really going away).
BlobUtils.remove(path).forEach(function(filename) {
BrambleEvents.triggerFileRemoved(filename);
});
callback();
});
}
function unlink(path, callback) {
path = decodePath(path);
_rmfr(path, callback);
}
function moveToTrash(path, callback) {
path = decodePath(path);
// TODO: do we want to support a .trash/ dir or the like?
unlink(path, callback);
_rmfr(path, callback);
}
function initWatchers(changeCallback, offlineCallback) {