Skip to content

Commit

Permalink
Added the attributes to the stored properties affected by PROPPATCH
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrienCastex committed Jun 29, 2017
1 parent 9d3b03e commit f8f6e00
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 27 deletions.
3 changes: 3 additions & 0 deletions lib/manager/v2/fileSystem/CommonTypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ export declare type SimpleCallback = (error?: Error) => void;
export declare type ReturnCallback<T> = (error?: Error, data?: T) => void;
export declare type Return2Callback<T1, T2> = (error?: Error, data1?: T1, data2?: T2) => void;
export declare type ResourcePropertyValue = string | XMLElement | XMLElement[];
export interface PropertyAttributes {
[name: string]: string;
}
export declare class ResourceType {
isFile: boolean;
isDirectory: boolean;
Expand Down
19 changes: 10 additions & 9 deletions lib/manager/v2/fileSystem/PropertyManager.d.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import { ReturnCallback, SimpleCallback, ResourcePropertyValue } from './CommonTypes';
import { ReturnCallback, Return2Callback, SimpleCallback, ResourcePropertyValue, PropertyAttributes } from './CommonTypes';
export interface PropertyBag {
[name: string]: ResourcePropertyValue;
[name: string]: {
value: ResourcePropertyValue;
attributes?: PropertyAttributes;
};
}
export interface IPropertyManager {
setProperty(name: string, value: ResourcePropertyValue, callback: SimpleCallback): void;
getProperty(name: string, callback: ReturnCallback<ResourcePropertyValue>): void;
setProperty(name: string, value: ResourcePropertyValue, attributes: PropertyAttributes, callback: SimpleCallback): void;
getProperty(name: string, callback: Return2Callback<ResourcePropertyValue, PropertyAttributes>): void;
removeProperty(name: string, callback: SimpleCallback): void;
getProperties(callback: ReturnCallback<PropertyBag>, byCopy?: boolean): void;
}
export declare class LocalPropertyManager implements IPropertyManager {
properties: {
[name: string]: ResourcePropertyValue;
};
setProperty(name: string, value: ResourcePropertyValue, callback: SimpleCallback): void;
getProperty(name: string, callback: ReturnCallback<ResourcePropertyValue>): void;
properties: PropertyBag;
setProperty(name: string, value: ResourcePropertyValue, attributes: PropertyAttributes, callback: SimpleCallback): void;
getProperty(name: string, callback: Return2Callback<ResourcePropertyValue, PropertyAttributes>): void;
removeProperty(name: string, callback: SimpleCallback): void;
getProperties(callback: ReturnCallback<PropertyBag>, byCopy?: boolean): void;
}
9 changes: 6 additions & 3 deletions lib/manager/v2/fileSystem/PropertyManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ var LocalPropertyManager = (function () {
function LocalPropertyManager() {
this.properties = {};
}
LocalPropertyManager.prototype.setProperty = function (name, value, callback) {
this.properties[name] = value;
LocalPropertyManager.prototype.setProperty = function (name, value, attributes, callback) {
this.properties[name] = {
value: value,
attributes: attributes
};
callback(null);
};
LocalPropertyManager.prototype.getProperty = function (name, callback) {
var property = this.properties[name];
callback(property ? null : Errors_1.Errors.PropertyNotFound, property);
callback(property ? null : Errors_1.Errors.PropertyNotFound, property.value, property.attributes);
};
LocalPropertyManager.prototype.removeProperty = function (name, callback) {
delete this.properties[name];
Expand Down
7 changes: 5 additions & 2 deletions lib/manager/v2/fileSystem/StandardMethods.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ var StandardMethods = (function () {
if (e)
return callback(e);
new Workflow_1.Workflow()
.each(Object.keys(props), function (name, cb) { return pmTo.setProperty(name, props[name], cb); })
.each(Object.keys(props), function (name, cb) {
var prop = props[name];
pmTo.setProperty(name, prop.value, prop.attributes, cb);
})
.error(callback)
.done(function () { return callback(); });
});
Expand Down Expand Up @@ -98,7 +101,7 @@ var StandardMethods = (function () {
var copyChildren = function (callback) {
fsFrom.readDir(ctx, subPathFrom, false, function (e, files) {
if (e)
callback(e);
return callback(e);
var subDepth = depth === -1 ? -1 : Math.max(0, depth - 1);
new Workflow_1.Workflow()
.each(files, function (file, cb) { return StandardMethods.standardCopy(ctx, subPathFrom.getChildPath(file), fsFrom, subPathTo.getChildPath(file), fsTo, overwrite, subDepth, function (e) { return cb(e); }); })
Expand Down
5 changes: 5 additions & 0 deletions src/manager/v2/fileSystem/CommonTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ export type Return2Callback<T1, T2> = (error ?: Error, data1 ?: T1, data2 ?: T2)

export type ResourcePropertyValue = string | XMLElement | XMLElement[]

export interface PropertyAttributes
{
[name : string] : string
}

export class ResourceType
{
static File = new ResourceType(true, false)
Expand Down
27 changes: 16 additions & 11 deletions src/manager/v2/fileSystem/PropertyManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,42 @@ import { Workflow } from '../../../helper/Workflow'
import { Errors } from '../../../Errors'
import { Lock } from '../../../resource/lock/Lock'
import { Path } from '../Path'
import { ReturnCallback, SimpleCallback, ResourcePropertyValue } from './CommonTypes'
import { ReturnCallback, Return2Callback, SimpleCallback, ResourcePropertyValue, PropertyAttributes } from './CommonTypes'
import * as mimeTypes from 'mime-types'
import * as crypto from 'crypto'

export interface PropertyBag
{
[name : string] : ResourcePropertyValue
[name : string] : {
value : ResourcePropertyValue
attributes ?: PropertyAttributes
}
}

export interface IPropertyManager
{
setProperty(name : string, value : ResourcePropertyValue, callback : SimpleCallback) : void
getProperty(name : string, callback : ReturnCallback<ResourcePropertyValue>) : void
setProperty(name : string, value : ResourcePropertyValue, attributes : PropertyAttributes, callback : SimpleCallback) : void
getProperty(name : string, callback : Return2Callback<ResourcePropertyValue, PropertyAttributes>) : void
removeProperty(name : string, callback : SimpleCallback) : void
getProperties(callback : ReturnCallback<PropertyBag>, byCopy ?: boolean) : void
}
export class LocalPropertyManager implements IPropertyManager
{
properties : {
[name : string] : ResourcePropertyValue
} = { };
properties : PropertyBag = { };

setProperty(name : string, value : ResourcePropertyValue, callback : SimpleCallback) : void
setProperty(name : string, value : ResourcePropertyValue, attributes : PropertyAttributes, callback : SimpleCallback) : void
{
this.properties[name] = value;
this.properties[name] = {
value,
attributes
};
callback(null);
}

getProperty(name : string, callback : ReturnCallback<ResourcePropertyValue>) : void
getProperty(name : string, callback : Return2Callback<ResourcePropertyValue, PropertyAttributes>) : void
{
const property = this.properties[name];
callback(property ? null : Errors.PropertyNotFound, property);
callback(property ? null : Errors.PropertyNotFound, property.value, property.attributes);
}

removeProperty(name : string, callback : SimpleCallback) : void
Expand Down
7 changes: 5 additions & 2 deletions src/manager/v2/fileSystem/StandardMethods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ export abstract class StandardMethods
return callback(e);

new Workflow()
.each(Object.keys(props), (name, cb) => pmTo.setProperty(name, props[name], cb))
.each(Object.keys(props), (name, cb) => {
const prop = props[name];
pmTo.setProperty(name, prop.value, prop.attributes, cb)
})
.error(callback)
.done(() => callback())
})
Expand Down Expand Up @@ -146,7 +149,7 @@ export abstract class StandardMethods
{
fsFrom.readDir(ctx, subPathFrom, false, (e, files) => {
if(e)
callback(e);
return callback(e);

const subDepth = depth === -1 ? -1 : Math.max(0, depth - 1);

Expand Down

0 comments on commit f8f6e00

Please sign in to comment.