diff --git a/native/v8_extensions/native.mm b/native/v8_extensions/native.mm index 71a975c8f..b34b68145 100644 --- a/native/v8_extensions/native.mm +++ b/native/v8_extensions/native.mm @@ -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); } diff --git a/spec/stdlib/fs-spec.coffee b/spec/stdlib/fs-spec.coffee index b0a6fae5f..94445d011 100644 --- a/spec/stdlib/fs-spec.coffee +++ b/spec/stdlib/fs-spec.coffee @@ -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) diff --git a/src/app/config.coffee b/src/app/config.coffee index 2940b33f4..7c22c362e 100644 --- a/src/app/config.coffee +++ b/src/app/config.coffee @@ -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: -> diff --git a/src/packages/fuzzy-finder/lib/load-paths-handler.coffee b/src/packages/fuzzy-finder/lib/load-paths-handler.coffee index 9ef442c99..ac7c338dc 100644 --- a/src/packages/fuzzy-finder/lib/load-paths-handler.coffee +++ b/src/packages/fuzzy-finder/lib/load-paths-handler.coffee @@ -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) diff --git a/src/stdlib/fs.coffee b/src/stdlib/fs.coffee index cac22e5fe..5d9ffe226 100644 --- a/src/stdlib/fs.coffee +++ b/src/stdlib/fs.coffee @@ -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