Return absolute paths from $native.traverseTree()

Previously relative paths were generated even though
things like fs.list() and fs.listTree() would just
recombine them with the root path.

Closes #391
This commit is contained in:
Kevin Sawicki 2013-03-08 13:42:31 -08:00
parent 110d3719bb
commit 8cf32149b7
5 changed files with 20 additions and 21 deletions

View File

@ -166,8 +166,7 @@ namespace v8_extensions {
}
else if (name == "traverseTree") {
std::string argument = arguments[0]->GetStringValue().ToString();
int rootPathLength = argument.size();
char rootPath[rootPathLength + 1];
char rootPath[argument.size() + 1];
strcpy(rootPath, argument.c_str());
char * const paths[] = {rootPath, NULL};
@ -191,12 +190,8 @@ namespace v8_extensions {
continue;
}
int pathLength = entry->fts_pathlen - rootPathLength;
char relative[pathLength + 1];
relative[pathLength] = '\0';
strncpy(relative, entry->fts_path + rootPathLength, pathLength);
args.clear();
args.push_back(CefV8Value::CreateString(relative));
args.push_back(CefV8Value::CreateString(entry->fts_path));
if (isFile) {
onFile->ExecuteFunction(onFile, args);
}

View File

@ -86,7 +86,7 @@ describe "fs", ->
it "calls fn for every path in the tree at the given path", ->
paths = []
onPath = (path) ->
paths.push(fs.join(fixturesDir, path))
paths.push(path)
true
fs.traverseTree fixturesDir, onPath, onPath
expect(paths).toEqual fs.listTree(fixturesDir)
@ -106,14 +106,16 @@ describe "fs", ->
expect(path).not.toMatch /\/dir\//
it "returns entries if path is a symlink", ->
symlinkPath = fs.join(fixturesDir, 'symlink-to-dir')
symlinkPaths = []
onSymlinkPath = (path) -> symlinkPaths.push(path)
onSymlinkPath = (path) -> symlinkPaths.push(path.substring(symlinkPath.length + 1))
regularPath = fs.join(fixturesDir, 'dir')
paths = []
onPath = (path) -> paths.push(path)
onPath = (path) -> paths.push(path.substring(regularPath.length + 1))
fs.traverseTree(fs.join(fixturesDir, 'symlink-to-dir'), onSymlinkPath, onSymlinkPath)
fs.traverseTree(fs.join(fixturesDir, 'dir'), onPath, onPath)
fs.traverseTree(symlinkPath, onSymlinkPath, onSymlinkPath)
fs.traverseTree(regularPath, onPath, onPath)
expect(symlinkPaths).toEqual(paths)

View File

@ -37,16 +37,16 @@ class Config
templateConfigDirPath = fs.resolve(window.resourcePath, 'dot-atom')
onConfigDirFile = (path) =>
templatePath = fs.join(templateConfigDirPath, path)
configPath = fs.join(@configDirPath, path)
fs.write(configPath, fs.read(templatePath))
relativePath = path.substring(templateConfigDirPath.length + 1)
configPath = fs.join(@configDirPath, relativePath)
fs.write(configPath, fs.read(path))
fs.traverseTree(templateConfigDirPath, onConfigDirFile, (path) -> true)
configThemeDirPath = fs.join(@configDirPath, 'themes')
onThemeDirFile = (path) ->
templatePath = fs.join(bundledThemesDirPath, path)
configPath = fs.join(configThemeDirPath, path)
fs.write(configPath, fs.read(templatePath))
relativePath = path.substring(bundledThemesDirPath.length + 1)
configPath = fs.join(configThemeDirPath, relativePath)
fs.write(configPath, fs.read(path))
fs.traverseTree(bundledThemesDirPath, onThemeDirFile, (path) -> true)
load: ->

View File

@ -13,8 +13,10 @@ module.exports =
return true if _.contains(ignoredNames, segment)
repo?.isPathIgnored(fs.join(rootPath, path))
onFile = (path) ->
path = path.substring(rootPath.length + 1)
paths.push(path) unless isIgnored(path)
onDirectory = (path) ->
path = path.substring(rootPath.length + 1)
not isIgnored(path)
fs.traverseTree(rootPath, onFile, onDirectory)

View File

@ -63,11 +63,11 @@ module.exports =
paths = []
if extensions
onPath = (path) =>
paths.push(@join(rootPath, path)) if _.contains(extensions, @extension(path))
paths.push(path) if _.contains(extensions, @extension(path))
false
else
onPath = (path) =>
paths.push(@join(rootPath, path))
paths.push(path)
false
@traverseTree(rootPath, onPath, onPath)
paths
@ -75,7 +75,7 @@ module.exports =
listTree: (rootPath) ->
paths = []
onPath = (path) =>
paths.push(@join(rootPath, path))
paths.push(path)
true
@traverseTree(rootPath, onPath, onPath)
paths