Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1359 from gosukiwi/master
Browse files Browse the repository at this point in the history
Do not wipe original file when duplicating
  • Loading branch information
sadick254 authored Oct 5, 2020
2 parents d5cc04d + 2fefb23 commit bf1181d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
16 changes: 1 addition & 15 deletions lib/copy-dialog.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class CopyDialog extends Dialog
@close()
return

unless @isNewPathValid(newPath)
if fs.existsSync(newPath)
@showError("'#{newPath}' already exists.")
return

Expand All @@ -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
27 changes: 27 additions & 0 deletions spec/tree-view-package-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit bf1181d

Please sign in to comment.