Skip to content

Commit

Permalink
Added 'source' header to read/write source of the files + Added the '…
Browse files Browse the repository at this point in the history
…canSource' privilege
  • Loading branch information
AdrienCastex committed May 22, 2017
1 parent 3cfdbea commit 842b37a
Show file tree
Hide file tree
Showing 41 changed files with 224 additions and 189 deletions.
10 changes: 5 additions & 5 deletions lib/resource/IResource.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ export interface IResource {
rename(newName: string, callback: Return2Callback<string, string>): any;
isSame(resource: IResource, callback: ReturnCallback<boolean>): any;
isOnTheSameFSWith(resource: IResource, callback: ReturnCallback<boolean>): any;
append(data: Int8Array, callback: SimpleCallback): any;
write(data: Int8Array, callback: SimpleCallback): any;
read(callback: ReturnCallback<Int8Array>): any;
mimeType(callback: ReturnCallback<string>): any;
size(callback: ReturnCallback<number>): any;
append(data: Int8Array, targetSource: boolean, callback: SimpleCallback): any;
write(data: Int8Array, targetSource: boolean, callback: SimpleCallback): any;
read(targetSource: boolean, callback: ReturnCallback<Int8Array>): any;
mimeType(targetSource: boolean, callback: ReturnCallback<string>): any;
size(targetSource: boolean, callback: ReturnCallback<number>): any;
getLocks(callback: ReturnCallback<Lock[]>): any;
setLock(lock: Lock, callback: SimpleCallback): any;
removeLock(uuid: string, callback: ReturnCallback<boolean>): any;
Expand Down
10 changes: 5 additions & 5 deletions lib/resource/physical/PhysicalFile.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ export declare class PhysicalFile extends PhysicalResource {
type(callback: ReturnCallback<ResourceType>): void;
create(callback: SimpleCallback): void;
delete(callback: SimpleCallback): void;
append(data: Int8Array, callback: SimpleCallback): void;
write(data: Int8Array, callback: SimpleCallback): void;
read(callback: ReturnCallback<Int8Array>): void;
mimeType(callback: ReturnCallback<string>): void;
size(callback: ReturnCallback<number>): void;
append(data: Int8Array, targetSource: boolean, callback: SimpleCallback): void;
write(data: Int8Array, targetSource: boolean, callback: SimpleCallback): void;
read(targetSource: boolean, callback: ReturnCallback<Int8Array>): void;
mimeType(targetSource: boolean, callback: ReturnCallback<string>): void;
size(targetSource: boolean, callback: ReturnCallback<number>): void;
addChild(resource: IResource, callback: SimpleCallback): void;
removeChild(resource: IResource, callback: SimpleCallback): void;
getChildren(callback: ReturnCallback<IResource[]>): void;
Expand Down
10 changes: 5 additions & 5 deletions lib/resource/physical/PhysicalFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var PhysicalFile = (function (_super) {
_this.removeFromParent(callback);
});
};
PhysicalFile.prototype.append = function (data, callback) {
PhysicalFile.prototype.append = function (data, targetSource, callback) {
var _this = this;
fs.appendFile(this.realPath, data, function (e) {
if (e)
Expand All @@ -53,7 +53,7 @@ var PhysicalFile = (function (_super) {
}
});
};
PhysicalFile.prototype.write = function (data, callback) {
PhysicalFile.prototype.write = function (data, targetSource, callback) {
var _this = this;
fs.writeFile(this.realPath, data, function (e) {
if (e)
Expand All @@ -64,14 +64,14 @@ var PhysicalFile = (function (_super) {
}
});
};
PhysicalFile.prototype.read = function (callback) {
PhysicalFile.prototype.read = function (targetSource, callback) {
fs.readFile(this.realPath, callback);
};
PhysicalFile.prototype.mimeType = function (callback) {
PhysicalFile.prototype.mimeType = function (targetSource, callback) {
var mt = mimeTypes.lookup(this.realPath);
callback(null, mt ? mt : 'application/octet-stream');
};
PhysicalFile.prototype.size = function (callback) {
PhysicalFile.prototype.size = function (targetSource, callback) {
fs.stat(this.realPath, function (e, s) { return callback(e, s ? s.size : null); });
};
PhysicalFile.prototype.addChild = function (resource, callback) {
Expand Down
10 changes: 5 additions & 5 deletions lib/resource/physical/PhysicalFolder.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ export declare class PhysicalFolder extends PhysicalResource {
type(callback: ReturnCallback<ResourceType>): void;
create(callback: SimpleCallback): void;
delete(callback: SimpleCallback): void;
append(data: Int8Array, callback: SimpleCallback): void;
write(data: Int8Array, callback: SimpleCallback): void;
read(callback: ReturnCallback<Int8Array>): void;
mimeType(callback: ReturnCallback<string>): void;
size(callback: ReturnCallback<number>): void;
append(data: Int8Array, targetSource: boolean, callback: SimpleCallback): void;
write(data: Int8Array, targetSource: boolean, callback: SimpleCallback): void;
read(targetSource: boolean, callback: ReturnCallback<Int8Array>): void;
mimeType(targetSource: boolean, callback: ReturnCallback<string>): void;
size(targetSource: boolean, callback: ReturnCallback<number>): void;
addChild(resource: IResource, callback: SimpleCallback): void;
removeChild(resource: IResource, callback: SimpleCallback): void;
getChildren(callback: ReturnCallback<IResource[]>): void;
Expand Down
12 changes: 6 additions & 6 deletions lib/resource/physical/PhysicalFolder.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,20 @@ var PhysicalFolder = (function (_super) {
});
});
};
PhysicalFolder.prototype.append = function (data, callback) {
PhysicalFolder.prototype.append = function (data, targetSource, callback) {
callback(Errors_1.Errors.InvalidOperation);
};
PhysicalFolder.prototype.write = function (data, callback) {
PhysicalFolder.prototype.write = function (data, targetSource, callback) {
callback(Errors_1.Errors.InvalidOperation);
};
PhysicalFolder.prototype.read = function (callback) {
PhysicalFolder.prototype.read = function (targetSource, callback) {
callback(Errors_1.Errors.InvalidOperation, null);
};
PhysicalFolder.prototype.mimeType = function (callback) {
PhysicalFolder.prototype.mimeType = function (targetSource, callback) {
callback(null, 'directory');
};
PhysicalFolder.prototype.size = function (callback) {
StandardResource_1.StandardResource.sizeOfSubFiles(this, callback);
PhysicalFolder.prototype.size = function (targetSource, callback) {
StandardResource_1.StandardResource.sizeOfSubFiles(this, targetSource, callback);
};
PhysicalFolder.prototype.addChild = function (resource, callback) {
var _this = this;
Expand Down
10 changes: 5 additions & 5 deletions lib/resource/physical/PhysicalResource.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ export declare abstract class PhysicalResource extends StandardResource {
rename(newName: string, callback: Return2Callback<string, string>): void;
webName(callback: ReturnCallback<string>): void;
abstract type(callback: ReturnCallback<ResourceType>): any;
abstract append(data: Int8Array, callback: SimpleCallback): any;
abstract write(data: Int8Array, callback: SimpleCallback): any;
abstract read(callback: ReturnCallback<Int8Array>): any;
abstract mimeType(callback: ReturnCallback<string>): any;
abstract size(callback: ReturnCallback<number>): any;
abstract append(data: Int8Array, targetSource: boolean, callback: SimpleCallback): any;
abstract write(data: Int8Array, targetSource: boolean, callback: SimpleCallback): any;
abstract read(targetSource: boolean, callback: ReturnCallback<Int8Array>): any;
abstract mimeType(targetSource: boolean, callback: ReturnCallback<string>): any;
abstract size(targetSource: boolean, callback: ReturnCallback<number>): any;
abstract addChild(resource: IResource, callback: SimpleCallback): any;
abstract removeChild(resource: IResource, callback: SimpleCallback): any;
abstract getChildren(callback: ReturnCallback<IResource[]>): any;
Expand Down
10 changes: 5 additions & 5 deletions lib/resource/std/RootResource.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ export declare class RootResource extends StandardResource {
rename(newName: string, callback: Return2Callback<string, string>): void;
webName(callback: ReturnCallback<string>): void;
type(callback: ReturnCallback<ResourceType>): void;
append(data: Int8Array, callback: SimpleCallback): void;
write(data: Int8Array, callback: SimpleCallback): void;
read(callback: ReturnCallback<Int8Array>): void;
mimeType(callback: ReturnCallback<string>): void;
size(callback: ReturnCallback<number>): void;
append(data: Int8Array, targetSource: boolean, callback: SimpleCallback): void;
write(data: Int8Array, targetSource: boolean, callback: SimpleCallback): void;
read(targetSource: boolean, callback: ReturnCallback<Int8Array>): void;
mimeType(targetSource: boolean, callback: ReturnCallback<string>): void;
size(targetSource: boolean, callback: ReturnCallback<number>): void;
addChild(resource: IResource, callback: SimpleCallback): void;
removeChild(resource: IResource, callback: SimpleCallback): void;
getChildren(callback: ReturnCallback<IResource[]>): void;
Expand Down
12 changes: 6 additions & 6 deletions lib/resource/std/RootResource.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,20 @@ var RootResource = (function (_super) {
RootResource.prototype.type = function (callback) {
callback(null, IResource_1.ResourceType.Directory);
};
RootResource.prototype.append = function (data, callback) {
RootResource.prototype.append = function (data, targetSource, callback) {
callback(Errors_1.Errors.InvalidOperation);
};
RootResource.prototype.write = function (data, callback) {
RootResource.prototype.write = function (data, targetSource, callback) {
callback(Errors_1.Errors.InvalidOperation);
};
RootResource.prototype.read = function (callback) {
RootResource.prototype.read = function (targetSource, callback) {
callback(Errors_1.Errors.InvalidOperation, null);
};
RootResource.prototype.mimeType = function (callback) {
RootResource.prototype.mimeType = function (targetSource, callback) {
callback(null, 'directory');
};
RootResource.prototype.size = function (callback) {
StandardResource_1.StandardResource.sizeOfSubFiles(this, callback);
RootResource.prototype.size = function (targetSource, callback) {
StandardResource_1.StandardResource.sizeOfSubFiles(this, targetSource, callback);
};
RootResource.prototype.addChild = function (resource, callback) {
var _this = this;
Expand Down
12 changes: 6 additions & 6 deletions lib/resource/std/StandardResource.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { LockKind } from '../lock/LockKind';
import { LockBag } from '../lock/LockBag';
import { Lock } from '../lock/Lock';
export declare abstract class StandardResource implements IResource {
static sizeOfSubFiles(resource: IResource, callback: ReturnCallback<number>): void;
static sizeOfSubFiles(resource: IResource, targetSource: boolean, callback: ReturnCallback<number>): void;
properties: object;
fsManager: FSManager;
lockBag: LockBag;
Expand All @@ -29,11 +29,11 @@ export declare abstract class StandardResource implements IResource {
abstract delete(callback: SimpleCallback): any;
abstract moveTo(parent: IResource, newName: string, override: boolean, callback: SimpleCallback): any;
abstract rename(newName: string, callback: Return2Callback<string, string>): any;
abstract append(data: Int8Array, callback: SimpleCallback): any;
abstract write(data: Int8Array, callback: SimpleCallback): any;
abstract read(callback: ReturnCallback<Int8Array>): any;
abstract mimeType(callback: ReturnCallback<string>): any;
abstract size(callback: ReturnCallback<number>): any;
abstract append(data: Int8Array, targetSource: boolean, callback: SimpleCallback): any;
abstract write(data: Int8Array, targetSource: boolean, callback: SimpleCallback): any;
abstract read(targetSource: boolean, callback: ReturnCallback<Int8Array>): any;
abstract mimeType(targetSource: boolean, callback: ReturnCallback<string>): any;
abstract size(targetSource: boolean, callback: ReturnCallback<number>): any;
creationDate(callback: ReturnCallback<number>): void;
lastModifiedDate(callback: ReturnCallback<number>): void;
abstract webName(callback: ReturnCallback<string>): any;
Expand Down
4 changes: 2 additions & 2 deletions lib/resource/std/StandardResource.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var StandardResource = (function () {
this.parent = parent;
this.dateLastModified = this.dateCreation;
}
StandardResource.sizeOfSubFiles = function (resource, callback) {
StandardResource.sizeOfSubFiles = function (resource, targetSource, callback) {
resource.getChildren(function (e, children) {
if (e) {
callback(e, null);
Expand All @@ -39,7 +39,7 @@ var StandardResource = (function () {
if (nb === 0)
callback(null, size);
}
children.forEach(function (c) { return c.size(go); });
children.forEach(function (c) { return c.size(targetSource, go); });
});
};
StandardResource.prototype.isSame = function (resource, callback) {
Expand Down
10 changes: 5 additions & 5 deletions lib/resource/virtual/VirtualFile.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ export declare class VirtualFile extends VirtualResource {
content: Int8Array;
constructor(name: string, parent?: IResource, fsManager?: FSManager);
type(callback: ReturnCallback<ResourceType>): void;
append(data: Int8Array, callback: SimpleCallback): void;
write(data: Int8Array, callback: SimpleCallback): void;
read(callback: ReturnCallback<Int8Array>): void;
mimeType(callback: ReturnCallback<string>): void;
size(callback: ReturnCallback<number>): void;
append(data: Int8Array, targetSource: boolean, callback: SimpleCallback): void;
write(data: Int8Array, targetSource: boolean, callback: SimpleCallback): void;
read(targetSource: boolean, callback: ReturnCallback<Int8Array>): void;
mimeType(targetSource: boolean, callback: ReturnCallback<string>): void;
size(targetSource: boolean, callback: ReturnCallback<number>): void;
addChild(resource: IResource, callback: SimpleCallback): void;
removeChild(resource: IResource, callback: SimpleCallback): void;
getChildren(callback: ReturnCallback<IResource[]>): void;
Expand Down
10 changes: 5 additions & 5 deletions lib/resource/virtual/VirtualFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var VirtualFile = (function (_super) {
VirtualFile.prototype.type = function (callback) {
callback(null, IResource_1.ResourceType.File);
};
VirtualFile.prototype.append = function (data, callback) {
VirtualFile.prototype.append = function (data, targetSource, callback) {
var newContent = new Int8Array(this.content.length + data.length);
for (var i = 0; i < this.content.length; ++i)
newContent[i] = this.content[i];
Expand All @@ -34,19 +34,19 @@ var VirtualFile = (function (_super) {
this.updateLastModified();
callback(null);
};
VirtualFile.prototype.write = function (data, callback) {
VirtualFile.prototype.write = function (data, targetSource, callback) {
this.content = data;
this.updateLastModified();
callback(null);
};
VirtualFile.prototype.read = function (callback) {
VirtualFile.prototype.read = function (targetSource, callback) {
callback(null, this.content);
};
VirtualFile.prototype.mimeType = function (callback) {
VirtualFile.prototype.mimeType = function (targetSource, callback) {
var mt = mimeTypes.lookup(this.name);
callback(null, mt ? mt : 'application/octet-stream');
};
VirtualFile.prototype.size = function (callback) {
VirtualFile.prototype.size = function (targetSource, callback) {
callback(null, this.content.length);
};
VirtualFile.prototype.addChild = function (resource, callback) {
Expand Down
10 changes: 5 additions & 5 deletions lib/resource/virtual/VirtualFolder.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ export declare class VirtualFolder extends VirtualResource {
children: ResourceChildren;
constructor(name: string, parent?: IResource, fsManager?: FSManager);
type(callback: ReturnCallback<ResourceType>): void;
append(data: Int8Array, callback: SimpleCallback): void;
write(data: Int8Array, callback: SimpleCallback): void;
read(callback: ReturnCallback<Int8Array>): void;
mimeType(callback: ReturnCallback<string>): void;
size(callback: ReturnCallback<number>): void;
append(data: Int8Array, targetSource: boolean, callback: SimpleCallback): void;
write(data: Int8Array, targetSource: boolean, callback: SimpleCallback): void;
read(targetSource: boolean, callback: ReturnCallback<Int8Array>): void;
mimeType(targetSource: boolean, callback: ReturnCallback<string>): void;
size(targetSource: boolean, callback: ReturnCallback<number>): void;
addChild(resource: IResource, callback: SimpleCallback): void;
removeChild(resource: IResource, callback: SimpleCallback): void;
getChildren(callback: ReturnCallback<IResource[]>): void;
Expand Down
12 changes: 6 additions & 6 deletions lib/resource/virtual/VirtualFolder.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,20 @@ var VirtualFolder = (function (_super) {
VirtualFolder.prototype.type = function (callback) {
callback(null, IResource_1.ResourceType.Directory);
};
VirtualFolder.prototype.append = function (data, callback) {
VirtualFolder.prototype.append = function (data, targetSource, callback) {
callback(Errors_1.Errors.InvalidOperation);
};
VirtualFolder.prototype.write = function (data, callback) {
VirtualFolder.prototype.write = function (data, targetSource, callback) {
callback(Errors_1.Errors.InvalidOperation);
};
VirtualFolder.prototype.read = function (callback) {
VirtualFolder.prototype.read = function (targetSource, callback) {
callback(Errors_1.Errors.InvalidOperation, null);
};
VirtualFolder.prototype.mimeType = function (callback) {
VirtualFolder.prototype.mimeType = function (targetSource, callback) {
callback(null, 'directory');
};
VirtualFolder.prototype.size = function (callback) {
StandardResource_1.StandardResource.sizeOfSubFiles(this, callback);
VirtualFolder.prototype.size = function (targetSource, callback) {
StandardResource_1.StandardResource.sizeOfSubFiles(this, targetSource, callback);
};
VirtualFolder.prototype.addChild = function (resource, callback) {
var _this = this;
Expand Down
10 changes: 5 additions & 5 deletions lib/resource/virtual/VirtualResource.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ export declare abstract class VirtualResource extends StandardResource {
rename(newName: string, callback: Return2Callback<string, string>): void;
webName(callback: ReturnCallback<string>): void;
abstract type(callback: ReturnCallback<ResourceType>): any;
abstract append(data: Int8Array, callback: SimpleCallback): any;
abstract write(data: Int8Array, callback: SimpleCallback): any;
abstract read(callback: ReturnCallback<Int8Array>): any;
abstract mimeType(callback: ReturnCallback<string>): any;
abstract size(callback: ReturnCallback<number>): any;
abstract append(data: Int8Array, targetSource: boolean, callback: SimpleCallback): any;
abstract write(data: Int8Array, targetSource: boolean, callback: SimpleCallback): any;
abstract read(targetSource: boolean, callback: ReturnCallback<Int8Array>): any;
abstract mimeType(targetSource: boolean, callback: ReturnCallback<string>): any;
abstract size(targetSource: boolean, callback: ReturnCallback<number>): any;
abstract addChild(resource: IResource, callback: SimpleCallback): any;
abstract removeChild(resource: IResource, callback: SimpleCallback): any;
abstract getChildren(callback: ReturnCallback<IResource[]>): any;
Expand Down
4 changes: 2 additions & 2 deletions lib/server/commands/Copy.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ function copy(arg, source, rDest, destination, callback) {
next();
return;
}
source.read(function (e, data) { return _(e, function () {
dest.write(data, function (e) { return _(e, next); });
source.read(true, function (e, data) { return _(e, function () {
dest.write(data, true, function (e) { return _(e, next); });
}); });
function next() {
if (!type.isDirectory) {
Expand Down
Loading

0 comments on commit 842b37a

Please sign in to comment.