diff --git a/spec/app/file-spec.coffee b/spec/app/file-spec.coffee index f47738081..4c429fa83 100644 --- a/spec/app/file-spec.coffee +++ b/spec/app/file-spec.coffee @@ -1,19 +1,20 @@ File = require 'file' fsUtils = require 'fs-utils' +path = require 'path' describe 'File', -> - [path, file] = [] + [filePath, file] = [] beforeEach -> - path = fsUtils.join(fsUtils.resolveOnLoadPath('fixtures'), "atom-file-test.txt") # Don't put in /tmp because /tmp symlinks to /private/tmp and screws up the rename test - fsUtils.remove(path) if fsUtils.exists(path) - fsUtils.write(path, "this is old!") - file = new File(path) + filePath = fsUtils.join(fsUtils.resolveOnLoadPath('fixtures'), "atom-file-test.txt") # Don't put in /tmp because /tmp symlinks to /private/tmp and screws up the rename test + fsUtils.remove(filePath) if fsUtils.exists(filePath) + fsUtils.write(filePath, "this is old!") + file = new File(filePath) file.read() afterEach -> file.off() - fsUtils.remove(path) if fsUtils.exists(path) + fsUtils.remove(filePath) if fsUtils.exists(filePath) describe "when the contents of the file change", -> it "triggers 'contents-changed' event handlers", -> @@ -46,7 +47,7 @@ describe 'File', -> newPath = null beforeEach -> - newPath = fsUtils.join(fsUtils.directory(path), "atom-file-was-moved-test.txt") + newPath = fsUtils.join(path.dirname(filePath), "atom-file-was-moved-test.txt") afterEach -> if fsUtils.exists(newPath) @@ -59,7 +60,7 @@ describe 'File', -> moveHandler = jasmine.createSpy('moveHandler') file.on 'moved', moveHandler - fsUtils.move(path, newPath) + fsUtils.move(filePath, newPath) waitsFor "move event", -> moveHandler.callCount > 0 @@ -76,7 +77,7 @@ describe 'File', -> changeHandler = jasmine.createSpy('changeHandler') file.on 'contents-changed', changeHandler - fsUtils.move(path, newPath) + fsUtils.move(filePath, newPath) waitsFor "move event", -> moveHandler.callCount > 0 @@ -100,12 +101,12 @@ describe 'File', -> expect(changeHandler).not.toHaveBeenCalled() - fsUtils.remove(path) + fsUtils.remove(filePath) expect(changeHandler).not.toHaveBeenCalled() waits 20 runs -> - fsUtils.write(path, "HE HAS RISEN!") + fsUtils.write(filePath, "HE HAS RISEN!") expect(changeHandler).not.toHaveBeenCalled() waitsFor "resurrection change event", -> @@ -113,7 +114,7 @@ describe 'File', -> runs -> expect(removeHandler).not.toHaveBeenCalled() - fsUtils.write(path, "Hallelujah!") + fsUtils.write(filePath, "Hallelujah!") changeHandler.reset() waitsFor "post-resurrection change event", -> diff --git a/spec/stdlib/fs-utils-spec.coffee b/spec/stdlib/fs-utils-spec.coffee index 04f5c8f32..8d680c4f2 100644 --- a/spec/stdlib/fs-utils-spec.coffee +++ b/spec/stdlib/fs-utils-spec.coffee @@ -21,18 +21,6 @@ describe "fsUtils", -> expect(fsUtils.isFile(fsUtils.join(fixturesDir, 'non-existent'))).toBe false expect(fsUtils.isFile(null)).toBe false - describe ".directory(path)", -> - describe "when called with a file path", -> - it "returns the path to the directory", -> - expect(fsUtils.directory(fsUtils.resolveOnLoadPath('fixtures/dir/a'))).toBe fsUtils.resolveOnLoadPath('fixtures/dir') - - describe "when called with a directory path", -> - it "return the path it was given", -> - expect(fsUtils.directory("/a/b/c")).toBe "/a/b" - expect(fsUtils.directory("/a")).toBe "" - expect(fsUtils.directory("a")).toBe "" - expect(fsUtils.directory("/a/b/c++")).toBe "/a/b" - describe ".exists(path)", -> it "returns true when path exsits", -> expect(fsUtils.exists(fsUtils.resolveOnLoadPath('fixtures'))).toBe true diff --git a/src/app/edit-session.coffee b/src/app/edit-session.coffee index 46b87f297..cdab28e8b 100644 --- a/src/app/edit-session.coffee +++ b/src/app/edit-session.coffee @@ -50,7 +50,7 @@ class EditSession @buffer.retain() @subscribe @buffer, "path-changed", => - @project.setPath(fsUtils.directory(@getPath())) unless @project.getPath()? + @project.setPath(path.dirname(@getPath())) unless @project.getPath()? @trigger "title-changed" @trigger "path-changed" @subscribe @buffer, "contents-conflicted", => @trigger "contents-conflicted" @@ -112,7 +112,7 @@ class EditSession getLongTitle: -> if sessionPath = @getPath() fileName = path.basename(sessionPath) - directory = path.basename(fsUtils.directory(sessionPath)) + directory = path.basename(path.dirname(sessionPath)) "#{fileName} - #{directory}" else 'untitled' diff --git a/src/app/project.coffee b/src/app/project.coffee index dfc11ae65..4747ebd6f 100644 --- a/src/app/project.coffee +++ b/src/app/project.coffee @@ -52,12 +52,12 @@ class Project # Sets the project path. # - # path - A {String} representing the new path - setPath: (path) -> + # projectPath - A {String} representing the new path + setPath: (projectPath) -> @rootDirectory?.off() - if path? - directory = if fsUtils.isDirectory(path) then path else fsUtils.directory(path) + if projectPath? + directory = if fsUtils.isDirectory(projectPath) then projectPath else path.dirname(projectPath) @rootDirectory = new Directory(directory) else @rootDirectory = null diff --git a/src/packages/package-generator/lib/package-generator-view.coffee b/src/packages/package-generator/lib/package-generator-view.coffee index dd2f2942f..afd27b5c6 100644 --- a/src/packages/package-generator/lib/package-generator-view.coffee +++ b/src/packages/package-generator/lib/package-generator-view.coffee @@ -46,7 +46,7 @@ class PackageGeneratorView extends View getPackagePath: -> packagePath = @miniEditor.getText() packageName = _.dasherize(path.basename(packagePath)) - fsUtils.join(fsUtils.directory(packagePath), packageName) + fsUtils.join(path.dirname(packagePath), packageName) validPackagePath: -> if fsUtils.exists(@getPackagePath()) @@ -70,7 +70,7 @@ class PackageGeneratorView extends View if fsUtils.isDirectory(path) fsUtils.makeTree(sourcePath) if fsUtils.isFile(path) - fsUtils.makeTree(fsUtils.directory(sourcePath)) + fsUtils.makeTree(path.dirname(sourcePath)) content = @replacePackageNamePlaceholders(fsUtils.read(path), packageName) fsUtils.write(sourcePath, content) diff --git a/src/packages/package-generator/spec/package-generator-spec.coffee b/src/packages/package-generator/spec/package-generator-spec.coffee index 98e0e66fc..5fea6e7c1 100644 --- a/src/packages/package-generator/spec/package-generator-spec.coffee +++ b/src/packages/package-generator/spec/package-generator-spec.coffee @@ -42,14 +42,14 @@ describe 'Package Generator', -> it "forces the package's name to be lowercase with dashes", -> packageName = "CamelCaseIsForTheBirds" - packagePath = fsUtils.join(fsUtils.directory(packagePath), packageName) + packagePath = fsUtils.join(path.dirname(packagePath), packageName) rootView.trigger("package-generator:generate") packageGeneratorView = rootView.find(".package-generator").view() packageGeneratorView.miniEditor.setText(packagePath) packageGeneratorView.trigger "core:confirm" expect(packagePath).not.toExistOnDisk() - expect(fsUtils.join(fsUtils.directory(packagePath), "camel-case-is-for-the-birds")).toExistOnDisk() + expect(fsUtils.join(path.dirname(packagePath), "camel-case-is-for-the-birds")).toExistOnDisk() it "correctly lays out the package files and closes the package generator view", -> rootView.attachToDom() diff --git a/src/packages/tabs/lib/tab-view.coffee b/src/packages/tabs/lib/tab-view.coffee index 9faaa89e9..08d7cb8dc 100644 --- a/src/packages/tabs/lib/tab-view.coffee +++ b/src/packages/tabs/lib/tab-view.coffee @@ -47,7 +47,7 @@ class TabView extends View if fileNameText? duplicates = @editor.getEditSessions().filter (session) -> fileNameText is session.buffer.getBaseName() if duplicates.length > 1 - directory = path.basename(fsUtils.directory(@editSession.getPath())) + directory = path.basename(path.dirname(@editSession.getPath())) fileNameText = "#{fileNameText} - #{directory}" if directory else fileNameText = 'untitled' diff --git a/src/packages/tree-view/lib/tree-view.coffee b/src/packages/tree-view/lib/tree-view.coffee index 50e2c70ba..85fa75072 100644 --- a/src/packages/tree-view/lib/tree-view.coffee +++ b/src/packages/tree-view/lib/tree-view.coffee @@ -235,7 +235,7 @@ class TreeView extends ScrollView dialog.showError("Error: #{newPath} already exists. Try a different path.") return - directoryPath = fsUtils.directory(newPath) + directoryPath = path.dirname(newPath) try fsUtils.makeTree(directoryPath) unless fsUtils.exists(directoryPath) fsUtils.move(oldPath, newPath) @@ -261,7 +261,7 @@ class TreeView extends ScrollView add: -> selectedEntry = @selectedEntry() or @root selectedPath = selectedEntry.getPath() - directoryPath = if fsUtils.isFile(selectedPath) then fsUtils.directory(selectedPath) else selectedPath + directoryPath = if fsUtils.isFile(selectedPath) then path.dirname(selectedPath) else selectedPath relativeDirectoryPath = project.relativize(directoryPath) relativeDirectoryPath += '/' if relativeDirectoryPath.length > 0 diff --git a/src/stdlib/command-installer.coffee b/src/stdlib/command-installer.coffee index aaee8b0df..6ef0dd86c 100644 --- a/src/stdlib/command-installer.coffee +++ b/src/stdlib/command-installer.coffee @@ -6,7 +6,7 @@ mkdirp = require 'mkdirp' fsUtils = require 'fs-utils' symlinkCommand = (sourcePath, destinationPath, callback) -> - mkdirp fsUtils.directory(destinationPath), (error) -> + mkdirp path.dirname(destinationPath), (error) -> if error? callback(error) else diff --git a/src/stdlib/fs-utils.coffee b/src/stdlib/fs-utils.coffee index 360207063..0d4f0a419 100644 --- a/src/stdlib/fs-utils.coffee +++ b/src/stdlib/fs-utils.coffee @@ -23,14 +23,6 @@ module.exports = catch e path - # Returns the path of a file's containing directory, albeit the - # parent directory if the file is a directory. A terminal directory - # separator is ignored. - directory: (path) -> - parentPath = path.replace(new RegExp("/#{Path.basename(_.escapeRegExp(path))}\/?$"), '') - return "" if path == parentPath - parentPath - # Returns true if the file specified by path exists exists: (path) -> path? and fs.existsSync(path)