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

Commit

Permalink
feat: use del to remove the files as a fallback when shouldDeletePerm…
Browse files Browse the repository at this point in the history
…anently
  • Loading branch information
aminya committed Dec 28, 2020
1 parent 6232215 commit 2c1f70b
Show file tree
Hide file tree
Showing 3 changed files with 258 additions and 10 deletions.
34 changes: 26 additions & 8 deletions lib/tree-view.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ _ = require 'underscore-plus'
{BufferedProcess, CompositeDisposable, Emitter} = require 'atom'
{repoForPath, getStyleObject, getFullExtension} = require "./helpers"
fs = require 'fs-plus'
del = require 'del'

AddDialog = require './add-dialog'
MoveDialog = require './move-dialog'
Expand Down Expand Up @@ -649,25 +650,42 @@ class TreeView
if shell.moveItemToTrash(selectedPath, shouldDeletePermanently)
@emitter.emit 'entry-deleted', {pathToDelete: selectedPath}
else
@emitter.emit 'delete-entry-failed', {pathToDelete: selectedPath}
if not shouldDeletePermanently
@emitter.emit 'delete-entry-failed', {pathToDelete: selectedPath}
failedDeletions.push selectedPath

if repo = repoForPath(selectedPath)
repo.getPathStatus(selectedPath)

if failedDeletions.length > 0
atom.notifications.addError @formatTrashFailureMessage(failedDeletions),
description: @formatTrashEnabledMessage()
detail: "#{failedDeletions.join('\n')}"
dismissable: true
if shouldDeletePermanently
del(selectedPaths, {force: true})
.then( deletedPaths ->
for deletedPath in deletedPaths
@emitter.emit 'entry-deleted', {pathToDelete: deletedPath}
)
.catch(err ->
atom.notifications.addError @formatTrashFailureMessage(failedDeletions, true),
description: err
dismissable: true
for selectedPath in selectedPaths
@emitter.emit 'delete-entry-failed', {pathToDelete: selectedPath}
)
.finally( -> finishRemoval(selectedEntries[0]))
else
atom.notifications.addError @formatTrashFailureMessage(failedDeletions, false),
description: @formatTrashEnabledMessage()
detail: "#{failedDeletions.join('\n')}"
dismissable: true

finishRemoval(selectedEntries[0])
if not shouldDeletePermanently
finishRemoval(selectedEntries[0])
)

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

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

formatTrashEnabledMessage: ->
switch process.platform
Expand Down

0 comments on commit 2c1f70b

Please sign in to comment.