From b5914f78af690712a500a499db7cdda27b24f0fb Mon Sep 17 00:00:00 2001 From: Andrew Koung Date: Sun, 7 Apr 2019 01:45:40 -0400 Subject: [PATCH] made request review changes --- src/filesystem/implementation.js | 50 ++++++++++++++++++++++++++++---- src/filesystem/interface.js | 1 - 2 files changed, 45 insertions(+), 6 deletions(-) diff --git a/src/filesystem/implementation.js b/src/filesystem/implementation.js index e9a6a9b..dbb371e 100644 --- a/src/filesystem/implementation.js +++ b/src/filesystem/implementation.js @@ -279,12 +279,52 @@ function find_node(context, path, callback) { } /** - * find_lnode + * find_symlink_node */ // in: file or directory path -// out: node structure, or error -function find_symbolic_node(context, path, callback) { - lstat_file(context, path, callback); +// out: symlink node structure, or error +function find_symlink_node(context, path, callback) { + path = normalize(path); + var name = basename(path); + var parentPath = dirname(path); + + var directoryNode; + var directoryData; + + if(ROOT_DIRECTORY_NAME === name) { + find_node(context, path, callback); + } else { + find_node(context, parentPath, read_directory_data); + } + + function read_directory_data(error, result) { + if(error) { + callback(error); + } else { + directoryNode = result; + context.getObject(directoryNode.data, check_if_file_exists); + } + } + + function create_node(error, data) { + if(error) { + return callback(error); + } + Node.create(data, callback); + } + + function check_if_file_exists(error, result) { + if(error) { + callback(error); + } else { + directoryData = result; + if(!directoryData.hasOwnProperty(name)) { + callback(new Errors.ENOENT('a component of the path does not name an existing file', path)); + } else { + context.getObject(directoryData[name].id, create_node); + } + } + } } /** @@ -2078,7 +2118,7 @@ function lchown_file(context, path, uid, gid, callback) { update_node_times(context, path, node, { mtime: Date.now() }, callback); } } - find_symbolic_node(context, path, update_owner); + find_symlink_node(context, path, update_owner); } function getxattr(context, path, name, callback) { diff --git a/src/filesystem/interface.js b/src/filesystem/interface.js index d6e9390..93e491b 100644 --- a/src/filesystem/interface.js +++ b/src/filesystem/interface.js @@ -341,7 +341,6 @@ function FileSystem(options, callback) { { name: 'futimes' }, { name: 'getxattr', promises: true, absPathArgs: [0] }, { name: 'lchown' }, - // lchmod - https://github.com/filerjs/filer/issues/619 { name: 'link', promises: true, absPathArgs: [0, 1] }, { name: 'lseek' }, { name: 'lstat', promises: true },