This commit is contained in:
Barry Tulchinsky 2013-12-20 03:34:05 -05:00
parent 848eb734b5
commit 5e61be5668
3 changed files with 51 additions and 3 deletions

View File

@ -6,6 +6,8 @@ define(function(require) {
var O_EXCLUSIVE = 'EXCLUSIVE';
var O_TRUNCATE = 'TRUNCATE';
var O_APPEND = 'APPEND';
var XATTR_CREATE = 'CREATE';
var XATTR_REPLACE = 'REPLACE';
return {
FILE_SYSTEM_NAME: 'local',
@ -53,6 +55,9 @@ define(function(require) {
'ax+': [O_WRITE, O_READ, O_CREATE, O_EXCLUSIVE, O_APPEND]
},
XATTR_CREATE: XATTR_CREATE,
XATTR_REPLACE: XATTR_REPLACE,
FS_READY: 'READY',
FS_PENDING: 'PENDING',
FS_ERROR: 'ERROR',

View File

@ -105,6 +105,13 @@ define(function(require) {
EFileSystemError.prototype.name = "EFileSystemError";
EFileSystemError.prototype.constructor = EFileSystemError;
function ENoAttr(message) {
this.message = message || '';
}
ENoAttr.prototype = new Error();
ENoAttr.prototype.name = 'ENoAttr';
ENoAttr.prototype.constructor = ENoAttr;
return {
EExists: EExists,
EIsDirectory: EIsDirectory,
@ -118,7 +125,8 @@ define(function(require) {
EInvalid: EInvalid,
EIO: EIO,
ELoop: ELoop,
EFileSystemError: EFileSystemError
EFileSystemError: EFileSystemError,
ENoAttr: ENoAttr
};
});

View File

@ -47,6 +47,8 @@ define(function(require) {
var O_TRUNCATE = require('src/constants').O_TRUNCATE;
var O_APPEND = require('src/constants').O_APPEND;
var O_FLAGS = require('src/constants').O_FLAGS;
var XATTR_CREATE = require('src/constants').XATTR_CREATE;
var XATTR_REPLACE = require('src/constants').XATTR_REPLACE;
var providers = require('src/providers/providers');
var adapters = require('src/adapters/adapters');
@ -1118,6 +1120,39 @@ define(function(require) {
}
}
function setxattr_file (context, path, name, value, flag, callback) {
path = normalize(path);
function set_xattr (error, node) {
if (flag == XATTR_CREATE && node[name]) {
callback(new EExists('attribute already exists'));
}
else if (flag == XATTR_REPLACE && !node[name]) {
callback(new ENoAttr('attribute does not exist'));
}
else {
node.xattr[name] = value;
context.put(node.id, node, callback);
}
}
if (typeof name != 'string') {
callback(new EInvalid('attribute name must be a string'));
}
else if (!name) {
callback(new EInvalid('attribute name cannot be an empty string'));
}
else if (!value) {
callback(new EInvalid('value cannot be empty'));
}
else if (flag && flag != XATTR_CREATE && flag != XATTR_REPLACE) {
callback(new EInvalid('invalid flag, must be null, XATTR_CREATE or XATTR_REPLACE'));
}
else {
find_node (context, path, set_xattr);
}
}
function validate_flags(flags) {
if(!_(O_FLAGS).has(flags)) {
return null;
@ -1536,7 +1571,7 @@ define(function(require) {
}
function _setxattr(context, path, name, value, callback) {
function _setxattr(context, path, name, value, flag, callback) {
if(!nullCheck(path, callback)) return;
function check_result (error) {
@ -1548,7 +1583,7 @@ define(function(require) {
}
};
setxattr_file (context, path, name, value, check_result);
setxattr_file (context, path, name, value, flags, check_result);
}
function _lseek(fs, context, fd, offset, whence, callback) {