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

Commit 283345c

Browse files
committed
feat: use del to remove the files as a fallback when shouldDeletePermanently
1 parent 6232215 commit 283345c

File tree

3 files changed

+253
-10
lines changed

3 files changed

+253
-10
lines changed

lib/tree-view.coffee

+21-8
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ _ = require 'underscore-plus'
55
{BufferedProcess, CompositeDisposable, Emitter} = require 'atom'
66
{repoForPath, getStyleObject, getFullExtension} = require "./helpers"
77
fs = require 'fs-plus'
8+
del = require 'del'
89

910
AddDialog = require './add-dialog'
1011
MoveDialog = require './move-dialog'
@@ -649,25 +650,37 @@ class TreeView
649650
if shell.moveItemToTrash(selectedPath, shouldDeletePermanently)
650651
@emitter.emit 'entry-deleted', {pathToDelete: selectedPath}
651652
else
652-
@emitter.emit 'delete-entry-failed', {pathToDelete: selectedPath}
653+
if not shouldDeletePermanently
654+
@emitter.emit 'delete-entry-failed', {pathToDelete: selectedPath}
653655
failedDeletions.push selectedPath
654656

655657
if repo = repoForPath(selectedPath)
656658
repo.getPathStatus(selectedPath)
657659

658660
if failedDeletions.length > 0
659-
atom.notifications.addError @formatTrashFailureMessage(failedDeletions),
660-
description: @formatTrashEnabledMessage()
661-
detail: "#{failedDeletions.join('\n')}"
662-
dismissable: true
661+
if shouldDeletePermanently
662+
del(selectedPaths, {force: true})
663+
.then( -> @emitter.emit 'entry-deleted', {pathToDelete: selectedPath})
664+
.catch(err ->
665+
atom.notifications.addError @formatTrashFailureMessage(failedDeletions, true),
666+
description: err
667+
dismissable: true
668+
)
669+
.finally( -> finishRemoval(selectedEntries[0]))
670+
else
671+
atom.notifications.addError @formatTrashFailureMessage(failedDeletions, false),
672+
description: @formatTrashEnabledMessage()
673+
detail: "#{failedDeletions.join('\n')}"
674+
dismissable: true
663675

664-
finishRemoval(selectedEntries[0])
676+
if not shouldDeletePermanently
677+
finishRemoval(selectedEntries[0])
665678
)
666679

667-
formatTrashFailureMessage: (failedDeletions) ->
680+
formatTrashFailureMessage: (failedDeletions, shouldDeletePermanently = false) ->
668681
fileText = if failedDeletions.length > 1 then 'files' else 'file'
669682

670-
"The following #{fileText} couldn't be moved to the trash."
683+
"The following #{fileText} couldn't be #{if shouldDeletePermanently then "deleted permanently" else "moved to the trash."}"
671684

672685
formatTrashEnabledMessage: ->
673686
switch process.platform

0 commit comments

Comments
 (0)