Merge branch 'staging' into locks

This commit is contained in:
yflory
2019-01-24 16:27:15 +01:00
42 changed files with 663 additions and 213 deletions

View File

@@ -212,6 +212,28 @@ define([
};
};
// Check if a given path is resolved to a shared folder or to the main drive
var _isInSharedFolder = function (Env, path) {
var resolved = _resolvePath(Env, path);
return typeof resolved.id === "number" ? resolved.id : false;
};
// Get the owned files in the main drive that are also duplicated in shared folders
var _isDuplicateOwned = function (Env, path, id) {
if (path && _isInSharedFolder(Env, path)) { return; }
var data = _getFileData(Env, id || Env.user.userObject.find(path));
if (!data) { return; }
if (!_ownedByMe(Env, data.owners)) { return; }
var channel = data.channel;
if (!channel) { return; }
var foldersUO = Object.keys(Env.folders).map(function (k) {
return Env.folders[k].userObject;
});
return foldersUO.some(function (uo) {
return uo.findChannels([channel]).length;
});
};
// Get a copy of the elements located in the given paths, with their files data
// Note: This function is only called to move files from a proxy to another
var _getCopyFromPaths = function (Env, paths, userObject) {
@@ -281,6 +303,10 @@ define([
var resolved = _resolvePaths(Env, data.paths);
var newResolved = _resolvePath(Env, data.newPath);
// NOTE: we can only copy when moving from one drive to another. We don't want
// duplicates in the same drive
var copy = data.copy;
if (!newResolved.userObject.isFolder(newResolved.path)) { return void cb(); }
nThen(function (waitFor) {
@@ -305,6 +331,8 @@ define([
Array.prototype.push.apply(ownedPads, _owned);
});
if (copy) { return; }
if (resolved.main.length) {
var rootPath = resolved.main[0].slice();
rootPath.pop();
@@ -338,6 +366,8 @@ define([
uoTo.copyFromOtherDrive(newResolved.path, obj.el, obj.data, obj.key);
});
if (copy) { return; }
// Remove the elements from the old location (without unpinning)
uoFrom.delete(paths, waitFor());
}
@@ -442,7 +472,24 @@ define([
// Delete paths from the main drive and get the list of pads to unpin
// We also get the list of owned pads that were removed
if (resolved.main.length) {
Env.user.userObject.delete(resolved.main, waitFor(function (err, _toUnpin, _ownedRemoved) {
var uo = Env.user.userObject;
if (Util.find(Env.settings, ['drive', 'hideDuplicate'])) {
// If we hide duplicate owned pads in our drive, we have
// to make sure we're not deleting a hidden own file
// from inside a folder we're trying to delete
resolved.main.forEach(function (p) {
var el = uo.find(p);
if (uo.isFile(el) || uo.isSharedFolder(el)) { return; }
var arr = [];
uo.getFilesRecursively(el, arr);
arr.forEach(function (id) {
if (_isDuplicateOwned(Env, null, id)) {
Env.user.userObject.add(Number(id), [UserObject.ROOT]);
}
});
});
}
uo.delete(resolved.main, waitFor(function (err, _toUnpin, _ownedRemoved) {
if (!Env.unpinPads || !_toUnpin) { return; }
Array.prototype.push.apply(toUnpin, _toUnpin);
ownedRemoved = _ownedRemoved;
@@ -740,13 +787,14 @@ define([
});
};
var create = function (proxy, edPublic, pinPads, unpinPads, loadSf, uoConfig) {
var create = function (proxy, data, uoConfig) {
var Env = {
pinPads: pinPads,
unpinPads: unpinPads,
loadSharedFolder: loadSf,
pinPads: data.pin,
unpinPads: data.unpin,
loadSharedFolder: data.loadSharedFolder,
cfg: uoConfig,
edPublic: edPublic,
edPublic: data.edPublic,
settings: data.settings,
user: {
proxy: proxy,
userObject: UserObject.init(proxy, uoConfig)
@@ -797,12 +845,13 @@ define([
}
}, cb);
};
var moveInner = function (Env, paths, newPath, cb) {
var moveInner = function (Env, paths, newPath, cb, copy) {
return void Env.sframeChan.query("Q_DRIVE_USEROBJECT", {
cmd: "move",
data: {
paths: paths,
newPath: newPath
newPath: newPath,
copy: copy
}
}, cb);
};
@@ -891,6 +940,7 @@ define([
if (fPath) {
// This is a shared folder, we have to fix the paths in the search results
results.forEach(function (r) {
r.inSharedFolder = true;
r.paths.forEach(function (p) {
Array.prototype.unshift.apply(p, fPath);
});
@@ -905,8 +955,8 @@ define([
var getRecentPads = function (Env) {
return Env.user.userObject.getRecentPads();
};
var getOwnedPads = function (Env, edPublic) {
return Env.user.userObject.getOwnedPads(edPublic);
var getOwnedPads = function (Env) {
return Env.user.userObject.getOwnedPads(Env.edPublic);
};
var getSharedFolderData = function (Env, id) {
@@ -918,10 +968,7 @@ define([
return obj;
};
var isInSharedFolder = function (Env, path) {
var resolved = _resolvePath(Env, path);
return typeof resolved.id === "number" ? resolved.id : false;
};
var isInSharedFolder = _isInSharedFolder;
/* Generic: doesn't need access to a proxy */
var isFile = function (Env, el, allowStr) {
@@ -967,10 +1014,13 @@ define([
return Env.user.userObject.hasFile(el, trashRoot);
};
var createInner = function (proxy, sframeChan, uoConfig) {
var isDuplicateOwned = _isDuplicateOwned;
var createInner = function (proxy, sframeChan, edPublic, uoConfig) {
var Env = {
cfg: uoConfig,
sframeChan: sframeChan,
edPublic: edPublic,
user: {
proxy: proxy,
userObject: UserObject.init(proxy, uoConfig)
@@ -1012,6 +1062,7 @@ define([
getSharedFolderData: callWithEnv(getSharedFolderData),
isInSharedFolder: callWithEnv(isInSharedFolder),
getUserObjectPath: callWithEnv(getUserObjectPath),
isDuplicateOwned: callWithEnv(isDuplicateOwned),
// Generic
isFile: callWithEnv(isFile),
isFolder: callWithEnv(isFolder),