@@ -736,15 +736,15 @@ M.delete_nodes = function(paths_to_delete, callback)
736736 end )
737737end
738738
739- M .trash_node = function (path , callback , noconfirm )
739+ M .trash_node = function (path , callback )
740740 local _ , name = utils .split_path (path )
741741
742742 log .trace (" Deleting node:" , path )
743743 local _type = " unknown"
744744 local stat = uv .fs_lstat (path )
745745 local children_count = 0
746746 if not stat then
747- log .warn (" Could not read file/dir:" , path , stat , " , attempting to delete anyway..." )
747+ log .warn (" Could not read file/dir:" , path , stat , " , attempting to trash anyway..." )
748748 -- Guess the type by whether it appears to have an extension
749749 if path :match (" %.(.+)$" ) then
750750 _type = " file"
@@ -775,7 +775,7 @@ M.trash_node = function(path, callback, noconfirm)
775775 end
776776 end
777777
778- local do_delete = function ()
778+ local do_trash = function ()
779779 local complete = vim .schedule_wrap (function ()
780780 events .fire_event (events .FILE_DELETED , path )
781781 if callback then
@@ -789,80 +789,47 @@ M.trash_node = function(path, callback, noconfirm)
789789 return
790790 end
791791
792- if _type ~= " directory" then
793- local success = uv .fs_unlink (path )
794- if not success then
795- return log .error (" Could not remove file: " .. path )
796- end
797- clear_buffer (path )
798- else
799- -- first try using native system commands, which are recursive
800- local success = false
801- if utils .is_windows then
802- local delete_ok , result =
803- utils .execute_command ({ " cmd.exe" , " /c" , " rmdir" , " /s" , " /q" , vim .fn .shellescape (path ) })
804- if not delete_ok then
805- log .debug (" Could not delete directory '" , path , " ' with rmdir: " , result )
806- else
807- log .info (" Deleted directory " , path )
808- success = true
809- end
810- else
811- local delete_ok , result = utils .execute_command ({ " rm" , " -Rf" , path })
812- if not delete_ok then
813- log .debug (" Could not delete directory '" , path , " ' with rm: " , result )
814- else
815- log .info (" Deleted directory " , path )
816- success = true
817- end
818- end
819-
820- -- Fallback to using libuv if native commands fail
821- if not success then
822- success = delete_dir (path )
823- if not success then
824- return log .error (" Could not remove directory: " .. path )
825- end
826- end
792+ local success , err = trash .trash ({ path })
793+ if not success then
794+ log .error (" Could not trash " .. path , err )
795+ return
827796 end
797+
828798 complete ()
829799 end
830800
831- if noconfirm then
832- do_delete ()
833- else
834- local msg = string.format (" Are you sure you want to delete '%s'?" , name )
835- if children_count > 0 then
836- msg = (" WARNING: Dir has %s %s! %s" ):format (
837- children_count ,
838- children_count == 1 and " child" or " children" ,
839- msg
840- )
841- end
842- inputs .confirm (msg , function (confirmed )
843- if confirmed then
844- do_delete ()
845- end
846- end )
801+ local msg = string.format (" Are you sure you want to trash '%s'?" , name )
802+ if children_count > 0 then
803+ msg = (" WARNING: Dir has %s %s! %s" ):format (
804+ children_count ,
805+ children_count == 1 and " child" or " children" ,
806+ msg
807+ )
847808 end
809+ inputs .confirm (msg , function (confirmed )
810+ if confirmed then
811+ do_trash ()
812+ end
813+ end )
848814end
849815
850- --- @param paths_to_delete string[]
816+ --- @param paths_to_trash string[]
851817--- @param callback fun ( path )?
852- M .trash_nodes = function (paths_to_delete , callback )
853- local msg = " Are you sure you want to delete " .. # paths_to_delete .. " items?"
818+ M .trash_nodes = function (paths_to_trash , callback )
819+ local msg = " Are you sure you want to delete " .. # paths_to_trash .. " items?"
854820 inputs .confirm (msg , function (confirmed )
855821 if not confirmed then
856822 return
857823 end
858824
859- for _ , path in ipairs (paths_to_delete ) do
860- M .trash_node (path , nil , true )
825+ local success , err = trash .trash (paths_to_trash )
826+ if not success then
827+ log .error (err )
861828 end
862829
863830 if callback then
864831 vim .schedule (function ()
865- callback (paths_to_delete [ # paths_to_delete ])
832+ callback (paths_to_trash [ # paths_to_trash ])
866833 end )
867834 end
868835 end )
0 commit comments