add error for relative paths

This commit is contained in:
Alan Kligman 2014-02-21 12:39:33 -05:00
parent ed206d68d8
commit 7fce631ad7
5 changed files with 109 additions and 63 deletions

81
dist/filer.js vendored
View File

@ -3067,6 +3067,20 @@ define('src/path',[],function() {
return splitPath(path)[3];
}
function isAbsolute(path) {
if(path.charAt(0) === '/') {
return true;
}
return false;
}
function isNull(path) {
if (('' + path).indexOf('\u0000') !== -1) {
return true;
}
return false;
}
// XXXidbfs: we don't support path.exists() or path.existsSync(), which
// are deprecated, and need a FileSystem instance to work. Use fs.stat().
@ -3079,7 +3093,9 @@ define('src/path',[],function() {
delimiter: ':',
dirname: dirname,
basename: basename,
extname: extname
extname: extname,
isAbsolute: isAbsolute,
isNull: isNull
};
});
@ -3992,7 +4008,7 @@ define('src/adapters/adapters',['require','src/adapters/zlib','src/adapters/cryp
});
define('src/fs',['require','nodash','encoding','src/path','src/path','src/path','src/shared','src/shared','src/shared','src/error','src/error','src/error','src/error','src/error','src/error','src/error','src/error','src/error','src/error','src/error','src/error','src/error','src/error','src/constants','src/constants','src/constants','src/constants','src/constants','src/constants','src/constants','src/constants','src/constants','src/constants','src/constants','src/constants','src/constants','src/constants','src/constants','src/constants','src/constants','src/constants','src/constants','src/constants','src/constants','src/providers/providers','src/adapters/adapters'],function(require) {
define('src/fs',['require','nodash','encoding','src/path','src/path','src/path','src/path','src/path','src/shared','src/shared','src/shared','src/error','src/error','src/error','src/error','src/error','src/error','src/error','src/error','src/error','src/error','src/error','src/error','src/error','src/error','src/constants','src/constants','src/constants','src/constants','src/constants','src/constants','src/constants','src/constants','src/constants','src/constants','src/constants','src/constants','src/constants','src/constants','src/constants','src/constants','src/constants','src/constants','src/constants','src/constants','src/constants','src/providers/providers','src/adapters/adapters'],function(require) {
var _ = require('nodash');
@ -4003,6 +4019,8 @@ define('src/fs',['require','nodash','encoding','src/path','src/path','src/path',
var normalize = require('src/path').normalize;
var dirname = require('src/path').dirname;
var basename = require('src/path').basename;
var isAbsolutePath = require('src/path').isAbsolute;
var isNullPath = require('src/path').isNull;
var guid = require('src/shared').guid;
var hash = require('src/shared').hash;
@ -5354,11 +5372,16 @@ define('src/fs',['require','nodash','encoding','src/path','src/path','src/path',
return options;
}
// nullCheck from https://github.com/joyent/node/blob/master/lib/fs.js
function nullCheck(path, callback) {
if (('' + path).indexOf('\u0000') !== -1) {
var er = new Error('Path must be a string without null bytes.');
callback(er);
function pathCheck(path, callback) {
var err;
if(isNullPath(path)) {
err = new Error('Path must be a string without null bytes.');
} else if(!isAbsolutePath(path)) {
err = new Error('Path must be absolute.');
}
if(err) {
callback(err);
return false;
}
return true;
@ -5494,7 +5517,7 @@ define('src/fs',['require','nodash','encoding','src/path','src/path','src/path',
FileSystem.adapters = adapters;
function _open(fs, context, path, flags, callback) {
if(!nullCheck(path, callback)) return;
if(!pathCheck(path, callback)) return;
function check_result(error, fileNode) {
if(error) {
@ -5530,7 +5553,7 @@ define('src/fs',['require','nodash','encoding','src/path','src/path','src/path',
}
function _mkdir(context, path, callback) {
if(!nullCheck(path, callback)) return;
if(!pathCheck(path, callback)) return;
function check_result(error) {
if(error) {
@ -5544,7 +5567,7 @@ define('src/fs',['require','nodash','encoding','src/path','src/path','src/path',
}
function _rmdir(context, path, callback) {
if(!nullCheck(path, callback)) return;
if(!pathCheck(path, callback)) return;
function check_result(error) {
if(error) {
@ -5558,7 +5581,7 @@ define('src/fs',['require','nodash','encoding','src/path','src/path','src/path',
}
function _stat(context, name, path, callback) {
if(!nullCheck(path, callback)) return;
if(!pathCheck(path, callback)) return;
function check_result(error, result) {
if(error) {
@ -5592,8 +5615,8 @@ define('src/fs',['require','nodash','encoding','src/path','src/path','src/path',
}
function _link(context, oldpath, newpath, callback) {
if(!nullCheck(oldpath, callback)) return;
if(!nullCheck(newpath, callback)) return;
if(!pathCheck(oldpath, callback)) return;
if(!pathCheck(newpath, callback)) return;
function check_result(error) {
if(error) {
@ -5607,7 +5630,7 @@ define('src/fs',['require','nodash','encoding','src/path','src/path','src/path',
}
function _unlink(context, path, callback) {
if(!nullCheck(path, callback)) return;
if(!pathCheck(path, callback)) return;
function check_result(error) {
if(error) {
@ -5646,7 +5669,7 @@ define('src/fs',['require','nodash','encoding','src/path','src/path','src/path',
function _readFile(fs, context, path, options, callback) {
options = validate_file_options(options, null, 'r');
if(!nullCheck(path, callback)) return;
if(!pathCheck(path, callback)) return;
var flags = validate_flags(options.flag || 'r');
if(!flags) {
@ -5715,7 +5738,7 @@ define('src/fs',['require','nodash','encoding','src/path','src/path','src/path',
function _writeFile(fs, context, path, data, options, callback) {
options = validate_file_options(options, 'utf8', 'w');
if(!nullCheck(path, callback)) return;
if(!pathCheck(path, callback)) return;
var flags = validate_flags(options.flag || 'w');
if(!flags) {
@ -5750,7 +5773,7 @@ define('src/fs',['require','nodash','encoding','src/path','src/path','src/path',
function _appendFile(fs, context, path, data, options, callback) {
options = validate_file_options(options, 'utf8', 'a');
if(!nullCheck(path, callback)) return;
if(!pathCheck(path, callback)) return;
var flags = validate_flags(options.flag || 'a');
if(!flags) {
@ -5783,7 +5806,7 @@ define('src/fs',['require','nodash','encoding','src/path','src/path','src/path',
}
function _getxattr (context, path, name, callback) {
if (!nullCheck(path, callback)) return;
if (!pathCheck(path, callback)) return;
function fetch_value (error, value) {
if (error) {
@ -5819,7 +5842,7 @@ define('src/fs',['require','nodash','encoding','src/path','src/path','src/path',
}
function _setxattr (context, path, name, value, flag, callback) {
if (!nullCheck(path, callback)) return;
if (!pathCheck(path, callback)) return;
function check_result (error) {
if (error) {
@ -5857,7 +5880,7 @@ define('src/fs',['require','nodash','encoding','src/path','src/path','src/path',
}
function _removexattr (context, path, name, callback) {
if (!nullCheck(path, callback)) return;
if (!pathCheck(path, callback)) return;
function remove_xattr (error) {
if (error) {
@ -5945,7 +5968,7 @@ define('src/fs',['require','nodash','encoding','src/path','src/path','src/path',
}
function _readdir(context, path, callback) {
if(!nullCheck(path, callback)) return;
if(!pathCheck(path, callback)) return;
function check_result(error, files) {
if(error) {
@ -5959,7 +5982,7 @@ define('src/fs',['require','nodash','encoding','src/path','src/path','src/path',
}
function _utimes(context, path, atime, mtime, callback) {
if(!nullCheck(path, callback)) return;
if(!pathCheck(path, callback)) return;
var currentTime = Date.now();
atime = (atime) ? atime : currentTime;
@ -6002,8 +6025,8 @@ define('src/fs',['require','nodash','encoding','src/path','src/path','src/path',
}
function _rename(context, oldpath, newpath, callback) {
if(!nullCheck(oldpath, callback)) return;
if(!nullCheck(newpath, callback)) return;
if(!pathCheck(oldpath, callback)) return;
if(!pathCheck(newpath, callback)) return;
function check_result(error) {
if(error) {
@ -6025,8 +6048,8 @@ define('src/fs',['require','nodash','encoding','src/path','src/path','src/path',
}
function _symlink(context, srcpath, dstpath, callback) {
if(!nullCheck(srcpath, callback)) return;
if(!nullCheck(dstpath, callback)) return;
if(!pathCheck(srcpath, callback)) return;
if(!pathCheck(dstpath, callback)) return;
function check_result(error) {
if(error) {
@ -6040,7 +6063,7 @@ define('src/fs',['require','nodash','encoding','src/path','src/path','src/path',
}
function _readlink(context, path, callback) {
if(!nullCheck(path, callback)) return;
if(!pathCheck(path, callback)) return;
function check_result(error, result) {
if(error) {
@ -6058,7 +6081,7 @@ define('src/fs',['require','nodash','encoding','src/path','src/path','src/path',
}
function _lstat(fs, context, path, callback) {
if(!nullCheck(path, callback)) return;
if(!pathCheck(path, callback)) return;
function check_result(error, result) {
if(error) {
@ -6073,7 +6096,7 @@ define('src/fs',['require','nodash','encoding','src/path','src/path','src/path',
}
function _truncate(context, path, length, callback) {
if(!nullCheck(path, callback)) return;
if(!pathCheck(path, callback)) return;
function check_result(error) {
if(error) {

8
dist/filer.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -19,9 +19,9 @@ var fs = new Filer.FileSystem({
//var data = new Uint8Array(buffer.length);
try {
fs.stat('/', function(error, stats) {
fs.readdir('./', function(error, files) {
if(error) throw error;
console.log('stats:', stats);
console.log('contents:', files);
});
} catch(e) {
console.error(e);

View File

@ -9,6 +9,8 @@ define(function(require) {
var normalize = require('src/path').normalize;
var dirname = require('src/path').dirname;
var basename = require('src/path').basename;
var isAbsolutePath = require('src/path').isAbsolute;
var isNullPath = require('src/path').isNull;
var guid = require('src/shared').guid;
var hash = require('src/shared').hash;
@ -1360,11 +1362,16 @@ define(function(require) {
return options;
}
// nullCheck from https://github.com/joyent/node/blob/master/lib/fs.js
function nullCheck(path, callback) {
if (('' + path).indexOf('\u0000') !== -1) {
var er = new Error('Path must be a string without null bytes.');
callback(er);
function pathCheck(path, callback) {
var err;
if(isNullPath(path)) {
err = new Error('Path must be a string without null bytes.');
} else if(!isAbsolutePath(path)) {
err = new Error('Path must be absolute.');
}
if(err) {
callback(err);
return false;
}
return true;
@ -1500,7 +1507,7 @@ define(function(require) {
FileSystem.adapters = adapters;
function _open(fs, context, path, flags, callback) {
if(!nullCheck(path, callback)) return;
if(!pathCheck(path, callback)) return;
function check_result(error, fileNode) {
if(error) {
@ -1536,7 +1543,7 @@ define(function(require) {
}
function _mkdir(context, path, callback) {
if(!nullCheck(path, callback)) return;
if(!pathCheck(path, callback)) return;
function check_result(error) {
if(error) {
@ -1550,7 +1557,7 @@ define(function(require) {
}
function _rmdir(context, path, callback) {
if(!nullCheck(path, callback)) return;
if(!pathCheck(path, callback)) return;
function check_result(error) {
if(error) {
@ -1564,7 +1571,7 @@ define(function(require) {
}
function _stat(context, name, path, callback) {
if(!nullCheck(path, callback)) return;
if(!pathCheck(path, callback)) return;
function check_result(error, result) {
if(error) {
@ -1598,8 +1605,8 @@ define(function(require) {
}
function _link(context, oldpath, newpath, callback) {
if(!nullCheck(oldpath, callback)) return;
if(!nullCheck(newpath, callback)) return;
if(!pathCheck(oldpath, callback)) return;
if(!pathCheck(newpath, callback)) return;
function check_result(error) {
if(error) {
@ -1613,7 +1620,7 @@ define(function(require) {
}
function _unlink(context, path, callback) {
if(!nullCheck(path, callback)) return;
if(!pathCheck(path, callback)) return;
function check_result(error) {
if(error) {
@ -1652,7 +1659,7 @@ define(function(require) {
function _readFile(fs, context, path, options, callback) {
options = validate_file_options(options, null, 'r');
if(!nullCheck(path, callback)) return;
if(!pathCheck(path, callback)) return;
var flags = validate_flags(options.flag || 'r');
if(!flags) {
@ -1721,7 +1728,7 @@ define(function(require) {
function _writeFile(fs, context, path, data, options, callback) {
options = validate_file_options(options, 'utf8', 'w');
if(!nullCheck(path, callback)) return;
if(!pathCheck(path, callback)) return;
var flags = validate_flags(options.flag || 'w');
if(!flags) {
@ -1756,7 +1763,7 @@ define(function(require) {
function _appendFile(fs, context, path, data, options, callback) {
options = validate_file_options(options, 'utf8', 'a');
if(!nullCheck(path, callback)) return;
if(!pathCheck(path, callback)) return;
var flags = validate_flags(options.flag || 'a');
if(!flags) {
@ -1789,7 +1796,7 @@ define(function(require) {
}
function _getxattr (context, path, name, callback) {
if (!nullCheck(path, callback)) return;
if (!pathCheck(path, callback)) return;
function fetch_value (error, value) {
if (error) {
@ -1825,7 +1832,7 @@ define(function(require) {
}
function _setxattr (context, path, name, value, flag, callback) {
if (!nullCheck(path, callback)) return;
if (!pathCheck(path, callback)) return;
function check_result (error) {
if (error) {
@ -1863,7 +1870,7 @@ define(function(require) {
}
function _removexattr (context, path, name, callback) {
if (!nullCheck(path, callback)) return;
if (!pathCheck(path, callback)) return;
function remove_xattr (error) {
if (error) {
@ -1951,7 +1958,7 @@ define(function(require) {
}
function _readdir(context, path, callback) {
if(!nullCheck(path, callback)) return;
if(!pathCheck(path, callback)) return;
function check_result(error, files) {
if(error) {
@ -1965,7 +1972,7 @@ define(function(require) {
}
function _utimes(context, path, atime, mtime, callback) {
if(!nullCheck(path, callback)) return;
if(!pathCheck(path, callback)) return;
var currentTime = Date.now();
atime = (atime) ? atime : currentTime;
@ -2008,8 +2015,8 @@ define(function(require) {
}
function _rename(context, oldpath, newpath, callback) {
if(!nullCheck(oldpath, callback)) return;
if(!nullCheck(newpath, callback)) return;
if(!pathCheck(oldpath, callback)) return;
if(!pathCheck(newpath, callback)) return;
function check_result(error) {
if(error) {
@ -2031,8 +2038,8 @@ define(function(require) {
}
function _symlink(context, srcpath, dstpath, callback) {
if(!nullCheck(srcpath, callback)) return;
if(!nullCheck(dstpath, callback)) return;
if(!pathCheck(srcpath, callback)) return;
if(!pathCheck(dstpath, callback)) return;
function check_result(error) {
if(error) {
@ -2046,7 +2053,7 @@ define(function(require) {
}
function _readlink(context, path, callback) {
if(!nullCheck(path, callback)) return;
if(!pathCheck(path, callback)) return;
function check_result(error, result) {
if(error) {
@ -2064,7 +2071,7 @@ define(function(require) {
}
function _lstat(fs, context, path, callback) {
if(!nullCheck(path, callback)) return;
if(!pathCheck(path, callback)) return;
function check_result(error, result) {
if(error) {
@ -2079,7 +2086,7 @@ define(function(require) {
}
function _truncate(context, path, length, callback) {
if(!nullCheck(path, callback)) return;
if(!pathCheck(path, callback)) return;
function check_result(error) {
if(error) {

View File

@ -193,6 +193,20 @@ define(function() {
return splitPath(path)[3];
}
function isAbsolute(path) {
if(path.charAt(0) === '/') {
return true;
}
return false;
}
function isNull(path) {
if (('' + path).indexOf('\u0000') !== -1) {
return true;
}
return false;
}
// XXXidbfs: we don't support path.exists() or path.existsSync(), which
// are deprecated, and need a FileSystem instance to work. Use fs.stat().
@ -205,7 +219,9 @@ define(function() {
delimiter: ':',
dirname: dirname,
basename: basename,
extname: extname
extname: extname,
isAbsolute: isAbsolute,
isNull: isNull
};
});