Skip to content

Commit

Permalink
VFS: Fixed usage of wrong method causing problems with 3p VFS modules (
Browse files Browse the repository at this point in the history
  • Loading branch information
andersevenrud committed Nov 16, 2016
1 parent d63a291 commit 2bc64ec
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 16 deletions.
16 changes: 16 additions & 0 deletions src/client/javascript/utils/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,22 @@
// FS
/////////////////////////////////////////////////////////////////////////////

/**
* Gets the path from a location
*
* @function getPathFromVirtual
* @memberof OSjs.Utils
*
* @param {String} str Path name
*
* @return {String}
*/
OSjs.Utils.getPathFromVirtual = function(str) {
str = str || '';
var res = str.split(/([A-z0-9\-_]+)\:\/\/(.*)/)[2] || '';
return res.replace(/^\/?/, '/');
};

/**
* Gets the protocol from a location
*
Expand Down
22 changes: 11 additions & 11 deletions src/client/javascript/vfs/mounts/dropbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
console.info('DropboxVFS::scandir()', item);

var mm = OSjs.Core.getMountManager();
var path = Utils.getPathProtocol(item.path);
var path = Utils.getPathFromVirtual(item.path);

function _finish(entries) {
var result = entries.map(function(iter) {
Expand Down Expand Up @@ -147,7 +147,7 @@
DropboxVFS.prototype.write = function(item, data, callback) {
console.info('DropboxVFS::write()', item);

var path = Utils.getPathProtocol(item.path);
var path = Utils.getPathFromVirtual(item.path);
this.client.writeFile(path, data, function(error, stat) {
callback(error, true);
});
Expand All @@ -158,7 +158,7 @@
options.arrayBuffer = true;

console.info('DropboxVFS::read()', item, options);
var path = Utils.getPathProtocol(item.path);
var path = Utils.getPathFromVirtual(item.path);

this.client.readFile(path, options, function(error, entries) {
callback(error, (error ? false : (entries instanceof Array ? entries.join('\n') : entries)));
Expand All @@ -167,33 +167,33 @@

DropboxVFS.prototype.copy = function(src, dest, callback) {
console.info('DropboxVFS::copy()', src, dest);
var spath = Utils.getPathProtocol(src.path);
var dpath = Utils.getPathProtocol(dest.path);
var spath = Utils.getPathFromVirtual(src.path);
var dpath = Utils.getPathFromVirtual(dest.path);
this.client.copy(spath, dpath, function(error) {
callback(error, !error);
});
};

DropboxVFS.prototype.move = function(src, dest, callback) {
console.info('DropboxVFS::move()', src, dest);
var spath = Utils.getPathProtocol(src.path);
var dpath = Utils.getPathProtocol(dest.path);
var spath = Utils.getPathFromVirtual(src.path);
var dpath = Utils.getPathFromVirtual(dest.path);
this.client.move(spath, dpath, function(error) {
callback(error, !error);
});
};

DropboxVFS.prototype.unlink = function(item, callback) {
console.info('DropboxVFS::unlink()', item);
var path = Utils.getPathProtocol(item.path);
var path = Utils.getPathFromVirtual(item.path);
this.client.unlink(path, function(error, stat) {
callback(error, !error);
});
};

DropboxVFS.prototype.mkdir = function(item, callback) {
console.info('DropboxVFS::mkdir()', item);
var path = Utils.getPathProtocol(item.path);
var path = Utils.getPathFromVirtual(item.path);
this.client.mkdir(path, function(error, stat) {
callback(error, !error);
});
Expand All @@ -210,7 +210,7 @@
DropboxVFS.prototype.fileinfo = function(item, callback) {
console.info('DropboxVFS::fileinfo()', item);

var path = Utils.getPathProtocol(item.path);
var path = Utils.getPathFromVirtual(item.path);
this.client.stat(path, path, function(error, response) {
var fileinfo = null;
if ( !error && response ) {
Expand All @@ -228,7 +228,7 @@

DropboxVFS.prototype.url = function(item, callback) {
console.info('DropboxVFS::url()', item);
var path = (typeof item === 'string') ? Utils.getPathProtocol(item) : Utils.getPathProtocol(item.path);
var path = (typeof item === 'string') ? Utils.getPathFromVirtual(item) : Utils.getPathFromVirtual(item.path);
this.client.makeUrl(path, {downloadHack: true}, function(error, url) {
callback(error, url ? url.url : false);
});
Expand Down
4 changes: 2 additions & 2 deletions src/client/javascript/vfs/mounts/googledrive.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@
}
});

var resolves = Utils.getPathProtocol(root).replace(/^\/+/, '').split('/');
var resolves = Utils.getPathFromVirtual(root).replace(/^\/+/, '').split('/');
resolves = resolves.filter(function(el) {
return el !== '';
});
Expand Down Expand Up @@ -737,7 +737,7 @@
}

var mm = OSjs.Core.getMountManager();
if ( Utils.dirname(dir.path) !== Utils.getPathProtocol(mm.getModuleProperty('GoogleDrive', 'root')) ) {
if ( Utils.dirname(dir.path) !== Utils.getPathFromVirtual(mm.getModuleProperty('GoogleDrive', 'root')) ) {
getParentPathId(dir, function(error, id) {
console.debug('GoogleDrive::mkdir()->getParentPathId()', id, 'of', dir);
if ( error || !id ) {
Expand Down
2 changes: 1 addition & 1 deletion src/client/javascript/vfs/mounts/localstorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
throw new TypeError('Expected p as String');
}

p = Utils.getPathProtocol(p).replace(/\/+/g, '/');
p = Utils.getPathFromVirtual(p).replace(/\/+/g, '/');

var path = par ? (Utils.dirname(p) || '/') : p;
if ( path !== '/' ) {
Expand Down
4 changes: 2 additions & 2 deletions src/client/javascript/vfs/mounts/onedrive.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@
}
}

var path = Utils.getPathProtocol(item.path).replace(/\/+/, '/');
var path = Utils.getPathFromVirtual(item.path).replace(/\/+/, '/');
if ( useParent ) {
path = Utils.dirname(path);
}
Expand Down Expand Up @@ -286,7 +286,7 @@

console.info('OneDrive::scandir()', item);

var relativePath = Utils.getPathProtocol(item.path);
var relativePath = Utils.getPathFromVirtual(item.path);

function _finished(error, result) {
console.groupEnd();
Expand Down

0 comments on commit 2bc64ec

Please sign in to comment.