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

Commit a589bca

Browse files
author
Winston Liu
authored
Merge pull request #1304 from atom/wl-cut-eexist
Error when trying to cut/paste a file that already exists
2 parents 9ac1c9e + 0958912 commit a589bca

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

lib/tree-view.coffee

+7-9
Original file line numberDiff line numberDiff line change
@@ -736,15 +736,13 @@ class TreeView
736736
fs.writeFileSync(newPath, fs.readFileSync(initialPath))
737737
@emitter.emit 'entry-copied', {initialPath, newPath}
738738
else if cutPaths
739-
# Only move the target if the cut target doesn't exist
740-
unless fs.existsSync(newPath)
741-
try
742-
@emitter.emit 'will-move-entry', {initialPath, newPath}
743-
fs.moveSync(initialPath, newPath)
744-
@emitter.emit 'entry-moved', {initialPath, newPath}
745-
catch error
746-
@emitter.emit 'move-entry-failed', {initialPath, newPath}
747-
atom.notifications.addWarning("Unable to paste paths: #{initialPaths}", detail: error.message)
739+
try
740+
@emitter.emit 'will-move-entry', {initialPath, newPath}
741+
fs.moveSync(initialPath, newPath)
742+
@emitter.emit 'entry-moved', {initialPath, newPath}
743+
catch error
744+
@emitter.emit 'move-entry-failed', {initialPath, newPath}
745+
atom.notifications.addWarning("Unable to paste paths: #{initialPaths}", detail: error.message)
748746

749747
add: (isCreatingFile) ->
750748
selectedEntry = @selectedEntry() ? @roots[0]

spec/tree-view-package-spec.coffee

+4-1
Original file line numberDiff line numberDiff line change
@@ -1845,7 +1845,7 @@ describe "TreeView", ->
18451845
expect(callback).toHaveBeenCalledWith({initialPath: filePath, newPath})
18461846

18471847
describe 'when the target destination file exists', ->
1848-
it 'does not move the cut file', ->
1848+
it 'emits a warning and does not move the cut file', ->
18491849
callback = jasmine.createSpy("onEntryMoved")
18501850
treeView.onEntryMoved(callback)
18511851

@@ -1858,6 +1858,9 @@ describe "TreeView", ->
18581858
expect(fs.existsSync(filePath)).toBeTruthy()
18591859
expect(callback).not.toHaveBeenCalled()
18601860

1861+
expect(atom.notifications.getNotifications().length).toBe(1)
1862+
expect(atom.notifications.getNotifications()[0].getMessage()).toContain('Unable to paste')
1863+
18611864
describe 'when the file is currently open', ->
18621865
beforeEach ->
18631866
waitForWorkspaceOpenEvent ->

0 commit comments

Comments
 (0)