diff --git a/lib/copy-dialog.coffee b/lib/copy-dialog.coffee index aa510d84..9b335d1e 100644 --- a/lib/copy-dialog.coffee +++ b/lib/copy-dialog.coffee @@ -23,7 +23,7 @@ class CopyDialog extends Dialog @close() return - unless @isNewPathValid(newPath) + if fs.existsSync(newPath) @showError("'#{newPath}' already exists.") return @@ -46,17 +46,3 @@ class CopyDialog extends Dialog @close() catch error @showError("#{error.message}.") - - isNewPathValid: (newPath) -> - try - oldStat = fs.statSync(@initialPath) - newStat = fs.statSync(newPath) - - # New path exists so check if it points to the same file as the initial - # path to see if the case of the file name is being changed on a on a - # case insensitive filesystem. - @initialPath.toLowerCase() is newPath.toLowerCase() and - oldStat.dev is newStat.dev and - oldStat.ino is newStat.ino - catch - true # new path does not exist so it is valid diff --git a/spec/tree-view-package-spec.coffee b/spec/tree-view-package-spec.coffee index 1af6b5d5..0482db8e 100644 --- a/spec/tree-view-package-spec.coffee +++ b/spec/tree-view-package-spec.coffee @@ -7,6 +7,17 @@ os = require 'os' Directory = require '../lib/directory' eventHelpers = require "./event-helpers" +isCaseSensitive = null +isFilesystemCaseSensitive = -> + if isCaseSensitive is null + tempPath = temp.path() + fs.writeFileSync(path.join(tempPath, 'case-sensitive-check.txt'), '') + isCaseSensitive = true + isCaseSensitive = false if fs.existsSync(path.join(tempPath, 'CASE-SENSITIVE-CHECK.txt')) + fs.unlinkSync(path.join(tempPath, 'case-sensitive-check.txt')) + + isCaseSensitive + waitForPackageActivation = -> waitsForPromise -> atom.packages.activatePackage('tree-view') @@ -2634,6 +2645,22 @@ describe "TreeView", -> expect(copyDialog.element).toHaveClass('error') expect(copyDialog.element.parentElement).toBeTruthy() + describe "when trying to duplicate a file with the same name but different case", -> + it "shows an error message and does not close the dialog", -> + runs -> + newPath = path.join(dirPath, "TEST-FILE.txt") + copyDialog.miniEditor.setText(newPath) + + atom.commands.dispatch copyDialog.element, 'core:confirm' + + if isFilesystemCaseSensitive() + expect(fs.existsSync(newPath)).toBeTruthy() + expect(atom.workspace.getActiveTextEditor().getPath()).toBe(newPath) + else + expect(copyDialog.errorMessage.textContent).toContain 'already exists' + expect(copyDialog.element).toHaveClass('error') + expect(copyDialog.element.parentElement).toBeTruthy() + describe "when 'core:cancel' is triggered on the copy dialog", -> it "removes the dialog and focuses the tree view", -> jasmine.attachToDOM(treeView.element)