open should follow symbolic links
This functionality is tested implicitly through tests in writefile, readfile
This commit is contained in:
parent
a95bf43069
commit
702dd1a3a3
36
src/fs.js
36
src/fs.js
|
@ -414,6 +414,8 @@ define(function(require) {
|
|||
var fileNode;
|
||||
var fileData;
|
||||
|
||||
var followedCount = 0;
|
||||
|
||||
if(ROOT_DIRECTORY_NAME == name) {
|
||||
if(_(flags).contains(O_WRITE)) {
|
||||
callback(new EIsDirectory('the named file is a directory and O_WRITE is set'));
|
||||
|
@ -446,7 +448,7 @@ define(function(require) {
|
|||
if(directoryEntry.type == MODE_DIRECTORY && _(flags).contains(O_WRITE)) {
|
||||
callback(new EIsDirectory('the named file is a directory and O_WRITE is set'));
|
||||
} else {
|
||||
read_object(objectStore, directoryEntry.id, set_file_node);
|
||||
read_object(objectStore, directoryEntry.id, check_if_symbolic_link);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -459,6 +461,38 @@ define(function(require) {
|
|||
}
|
||||
}
|
||||
|
||||
function check_if_symbolic_link(error, result) {
|
||||
if(error) {
|
||||
callback(error);
|
||||
} else {
|
||||
var node = result;
|
||||
if(node.mode == MODE_SYMBOLIC_LINK) {
|
||||
followedCount++;
|
||||
if(followedCount > SYMLOOP_MAX){
|
||||
callback(new ELoop('too many symbolic links were encountered'));
|
||||
} else {
|
||||
follow_symbolic_link(node.data);
|
||||
}
|
||||
} else {
|
||||
set_file_node(undefined, node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function follow_symbolic_link(data) {
|
||||
data = normalize(data);
|
||||
parentPath = dirname(data);
|
||||
name = basename(data);
|
||||
if(ROOT_DIRECTORY_NAME == name) {
|
||||
if(_(flags).contains(O_WRITE)) {
|
||||
callback(new EIsDirectory('the named file is a directory and O_WRITE is set'));
|
||||
} else {
|
||||
find_node(objectStore, path, set_file_node);
|
||||
}
|
||||
}
|
||||
find_node(objectStore, parentPath, read_directory_data);
|
||||
}
|
||||
|
||||
function set_file_node(error, result) {
|
||||
if(error) {
|
||||
callback(error);
|
||||
|
|
|
@ -1063,6 +1063,36 @@ describe('fs.writeFile, fs.readFile', function() {
|
|||
});
|
||||
});
|
||||
|
||||
it('should follow symbolic links', function () {
|
||||
var complete = false;
|
||||
var _result;
|
||||
var that = this;
|
||||
|
||||
var contents = "This is a file.";
|
||||
|
||||
that.fs.writeFile('/myfile', '', { encoding: 'utf8' }, function(error) {
|
||||
if(error) throw error;
|
||||
that.fs.symlink('/myfile', '/myFileLink', function (error) {
|
||||
if (error) throw error;
|
||||
that.fs.writeFile('/myFileLink', contents, 'utf8', function (error) {
|
||||
if (error) throw error;
|
||||
that.fs.readFile('/myFileLink', 'utf8', function(error, data) {
|
||||
if(error) throw error;
|
||||
_result = data;
|
||||
complete = true;
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
waitsFor(function() {
|
||||
return complete;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
|
||||
runs(function() {
|
||||
expect(_result).toEqual(contents);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('fs.read', function() {
|
||||
|
|
Loading…
Reference in New Issue