Comments on the Trash

Moderator: BarryK

Post Reply
Caramel
Posts: 320
Joined: Sun Oct 02, 2022 6:25 pm
Location: France
Has thanked: 78 times
Been thanked: 51 times

Comments on the Trash

Post by Caramel »

In EasyOs (and probably classic pups), the Trash is both an application (more precisely a Rox-app) and a directory.

Results of some observations .

-Bug with Trash when EasyOs is used in French: When restoring a file, the pupdialog that prevents overwriting an existing file of the same name do not work. It's a bug in pupdialog (see viewtopic.php?t=10710)

-If you put a file in Trash, put a directory that contained this file in Trash, and finally want to restore the file, the file is lost.

-If you delete a directory, then recreate the directory at the same place, and finally want restore the directory, there is no option to combine the files that was in the directory at the time of the trashing and files added in the directory after the recreation

The principal problem for me is the incompatibility with the the Trash specs of FreeDesktop.org (https://specifications.freedesktop.org/ ... atest.html)
Most file managers other than ROX-Filer follow these recommendations.

An example is with the file manager XFE (Available by pkgget in Easy Buster or EasyVoid, a version compiled in Easy 5.7 is available here : viewtopic.php?p=111906#p111906)
If you put a file in Trash in XFE, this file is not available by the Trash icon and vice versa

In the puppy standard the Trash repository is /root/.Trash, in the freedesktop standard it's $HOME/. local/share/Trash (there is a directory by user, for root it's /root/.local/share/Trash)

Moreover the structures of the Trash directories are different according the standards.

In puppy/easy each file or directory putted in the Trash corresponds to a RoX-app in the Trash directory. This ROX-app(as a directory) contains the trashed file (or directory), information including the original path of the file and the date of the trashing

In the freedesktop standard the trashed files(or directories) are placed in the subdirectoy files of the Trash (in $HOME/.local/share/Trash/files). It's the directory that is opened when you open the Trash in XFE.
To each trashed file (or trashed directory), there is a corresponding info file in the subdirectory info of the Trash directory. (Remark :If a directory is trashed, the files it contained are moved in the Trash files directory with the directory. They are still in the trashed directory. No info file is created for these files)
The info file contains the original path of the file and the date of the trashing

XFE seems a good choice if you give importance to the Trash. Unfortunately, the option to really delete a file is greyed in XFE. You can empty the Trash but not delete a part of the Trash.

Another possibility to use the freedesktop standard is to use the commands provided by trash-cli (https://github.com/andreafrancia/trash-cli)
But the command trash-rm, to remove individual files from the Trash, has limits if 2 files in the Trash have the same name

Caramel
Posts: 320
Joined: Sun Oct 02, 2022 6:25 pm
Location: France
Has thanked: 78 times
Been thanked: 51 times

Experimental alternative to the Easy/Puppy Trash

Post by Caramel »

Experimental alternative to the Easy/Puppy Trash compatible with the trash specs of freedesktop and the Trash in XFE.

It's incomplete and i do not know if i will continue

Useless if you use only Rox as file manager.

Code: Select all

#!/bin/bash

#Based on the  ROX-app Trash of EasyOS 5.7. Modified to be compatible with the Trash specs of Freedesktop (https://specifications.freedesktop.org/trash-spec/trashspec-latest.html) and the Trash used by the file manager XFE


export TEXTDOMAIN=trash
export OUTPUT_CHARSET=UTF-8

# Create the Trash directory if it does not already exist.
[ -d /$HOME/.local/share/Trash ] || mkdir -p /$HOME/.local/share/Trash/{files,info}

# Determine the path to this application.
APPDIR=`dirname "$0"`
cd "$APPDIR"
APPDIR="`pwd`"
actual=`date +%F'T'%H:%M:%S`

# Set icon paths
fullicon="/usr/local/lib/X11/pixmaps/trashcan_full48.png"
emptyicon="/usr/local/lib/X11/pixmaps/trashcan_empty48.png"

# Play the trash sound. 20230610 fix.
function PlaySound
{
 if [ -e /proc/asound/card0 ];then
  timeout 3 aplay /usr/share/audio/generic.wav
 fi
}

# Play the trash sound. 20230610 fix.
function PlaySoundTrashIt
{
 if [ -e /proc/asound/card0 ];then
  timeout 3 aplay /usr/share/audio/generic.wav
 fi
}

function EmptyIcon
{
 ln -sf "$emptyicon" "$APPDIR/.DirIcon"
 cd ${HOME}
 rox -x "$APPDIR"
}

function FullIcon
{
 ln -sf "$fullicon" "$APPDIR/.DirIcon"
 cd ${HOME}
 rox -x "$APPDIR"
}

# Find the name of the file.
function notAForwardSlash
{
fSlash=/
 if [[ $1 != $fSlash ]]

  then
   return 0
  else
   return 1
 fi
}

function getFileName
{
 STRING="$1"
 LENGTH=${#STRING}
 for ((n=0;n <= $LENGTH; n++))
 do
   CHAR=${STRING:$n:1}
   if notAForwardSlash $CHAR
   then
    FileName=$FileName$CHAR
   else
    FileName=""
   fi
 done
}

function MoveToTrash
{
 getFileName "$m"
 # Create the trashinfo file
 InfoFile="$FileName"_$$.trashinfo
 NewFileName="$FileName"_$$
 if test ! -e "$HOME/.local/share/Trash/info/$InfoFile" ; then
  touch "$HOME/.local/share/Trash/info/$InfoFile"
  echo "[Trash Info]
Path=$m
DeletionDate=$actual" > "$HOME/.local/share/Trash/info/$InfoFile"
 fi
  # move the item to the Trash directory.
 mv "$m" "$HOME/.local/share/Trash/files/$NewFileName"
}

#function RemoveOldRoxIcon
#{
 #while grep ">$m<" /$HOME/Choices/ROX-Filer/PuppyPin
 #do
  #number=`grep -m 1 ">$m<" /$HOME/Choices/ROX-Filer/PuppyPin`
  ## Write the new PuppyPin file with the trashed item removed.
  #gawk -v var="$number" '{sub(var, ""); print}' /$HOME/Choices/ROX-Filer/PuppyPin > /$HOME/Choices/ROX-Filer/PuppyPin1
  ## Rename the new PuppyPin file
  #mv /$HOME/Choices/ROX-Filer/PuppyPin1 /$HOME/Choices/ROX-Filer/PuppyPin
  ## Restart the pinboard.
  #rox -p /$HOME/Choices/ROX-Filer/PuppyPin
 #done
#}

function ListFilesinTrashcan
{
 # retrieve information from the trashinfo files in a file list
/tmp/listinfos0
  ls -A /root/.local/share/Trash/info/ | while read line
  do 
  PathInfoFile=/root/.local/share/Trash/info/$line
  cat "$PathInfoFile" | tr '\n' '|' | sed 's/\[Trash Info]/\n/'; done \
| sed 's/Path=//' | sed '/DeletionDate/s/T/ /' | sed 's/DeletionDate=//' | sed 1d >> /tmp/listinfos0
  sync
  cut -c 2- /tmp/listinfos0 > /tmp/listinfos # delete the initial | of each line
  # create a list with the answer at the question "is it a directory" for each item in the trashcan
  ls -Al /root/.local/share/Trash/files/ | cut -c 1 | sed s/-/no/g | sed s/d/yes/g | awk ' NR > 1 { printf $0"|\n" }' > /tmp/listtestdirectory
  # create a list with the full size of each item
/tmp/listnewnamesfiles
  ls -A /root/.local/share/Trash/files/ | while read line; do du -sbh "/root/.local/share/Trash/files/$line" >> /tmp/listnewnamesfiles; done
  cat /tmp/listnewnamesfiles | awk '{ printf $1"|\n" }' > /tmp/listsizes
  # create a list of all the items (with their names in the trashcan that could different from their original names. For avoid collisions a number could have be added)
  ls -A /root/.local/share/Trash/files/ > /tmp/listnames
  
  # create a file that lists all items with informations (original path, deletion date, Directory or not, size, name in trashcan)
/tmp/trashitems
  paste /tmp/listinfos /tmp/listtestdirectory /tmp/listsizes /tmp/listnames >> /tmp/trashitems
}


# If they chose the "Look in the Trash" option.
if [ "$1" = "-look" ]
then
  if command -v xfe &> /dev/null
 then
  exec xfe /$HOME/.local/share/Trash/files
 else
  exec rox /$HOME/.local/share/Trash/{files,info}
 fi

# If they chose the "View Summary" option.
elif [ "$1" = "-summary" ]
then
 ListFilesinTrashcan
 export SUMMARY_DIALOG='
 <window title="'$(gettext 'All this is in the trash!')'" icon-name="gtk-delete">
  <vbox>
    <tree>
      <label>"'$(gettext 'Original Path|Deletion Date|Is directory?|Size|Name in trashcan')'"</label>
      <input>cat /tmp/trashitems</input>
      <height>570</height><width>790</width>
    </tree>
    <hbox>
      <button ok></button>
    </hbox>
  </vbox>
 </window>
 '
gtkdialog3 --program=SUMMARY_DIALOG --center
 rm /tmp/trashitems

# If they chose the "Empty the Trash" option.
elif [ "$1" = "-empty" ]
then
 #confirmation dialog starts here
 ls -A /$HOME/.local/share/Trash/files > /tmp/trash-deletelist
 export ConfirmDialog='
	<window title="'$(gettext 'Confirm Action')'" icon-name="gtk-delete">
		<frame '$(gettext 'Delete file(s)')'>
		<vbox scrollable="true" height="150" width="250">
			<text><input file>/tmp/trash-deletelist</input></text>
		</vbox>
		<hbox>
			<button use-stock="true" label="gtk-delete"></button>
			<button cancel></button>
		</hbox>
		</frame>
    </window>
 '
 I=$IFS; IFS=""
 for STATEMENTS in $(gtkdialog3 --program=ConfirmDialog --center) ; do
	eval $STATEMENTS
 done
 IFS=$I
 rm /tmp/trash-deletelist
 [ "$EXIT" != "OK" ] && exit
 # new confirmation dialog ends here..
  
## If they chose to delete. rm -r /$HOME/.Trash/files/* rm -r /$HOME/.Trash/files/.* rm -r /$HOME/.Trash/info/* rm -r /$HOME/.Trash/info/.* EmptyIcon PlaySoundTrashIt ### If they chose to "Quickly Empty the Trash". #elif [ "$1" = "-empty-quick" ] #then #rm -r /$HOME/.Trash/* #EmptyIcon #PlaySoundTrashIt else # Check to see if they clicked on the application or sent a file or directory to be deleted. #test -sd "$@" # # Changed 14.02.2013 Caused error /tmp/xerrs.log # test -z "$*" if [ "$?" = "0" ] then # If they just clicked on the icon. if [ "`ls -A $HOME/.local/share/Trash/files`" = "" ] then EmptyIcon yad --text="$(gettext 'The trashcan is empty')" --button="gtk-ok:0" else if command -v xfe &> /dev/null then exec xfe /$HOME/.local/share/Trash/files else exec rox /$HOME/.local/share/Trash/{files,info} fi fi else # If they sent something to the trash can. for m in "$@" do ## Test to see if the item is a symbolic link. #if [ -h "$m" ] #then ## Write the confirmation message. ##MSG=`which gxmessage` || MSG=xmessage ##$MSG -buttons "Yes:21,No" -default Yes -center -title "Confirm Action" "The item $m is a Symbolic Link. ##This will move the Symbolic Link to the Trash and leave the original item alone. ##Do you want to continue?" ## If they chose to cancel. ##[ $? -eq 21 ] || exit ## ##new confrimation dialog starts here.. #pupdialog --title "$(gettext 'Confirm Action')" --yes-label "$(gettext 'Move to Trash')" --no-label "$(gettext 'Cancel')" --yesno "$m $(gettext 'is a Symbolic Link. This will move the Symbolic Link to the Trash and leave the original item alone. Do you want to continue?')" 2> /root/test2 #[ $? -eq 0 ] || exit ##new confirmation dialog ends here.. #fi #match=`grep ">$m<" /$HOME/Choices/ROX-Filer/PuppyPin` ## Test $match to see if the item had a link to it on the pinboard. #test "$match" #if [ "$?" = "0" ] #then #pupdialog --title "$(gettext 'Confirm Action')" --yes-label "$(gettext 'Move to Trash')" --no-label "$(gettext 'Cancel')" --yesno "$m $(gettext 'There is one or more Desktop shortcuts pointing to this file. This will move the original item to the Trash and remove the shortcut(s) from the Desktop. Do you want to continue?')" #[ $? -eq 0 ] || exit #while check=`grep ">$m<" /$HOME/Choices/ROX-Filer/PuppyPin` #do #OldNumber=`grep -c ">$m<" /$HOME/Choices/ROX-Filer/PuppyPin` ## Get the filename again #getFileName "$m" ## Add a suffix if the item is a hidden file/directory #FileName=${FileName/#./HIDDEN-} ## Create directories for the trashed item. #mkdir "$HOME/.Trash/$FileName-$$" ## Create the shortcut file info #echo "$match" > "$HOME/.Trash/$FileName-$$/shortcut" #shortcuts="true" #rox --RPC << EOF #<?xml version="1.0"?> #<env:Envelope xmlns:env="http://www.w3.org/2001/12/soap-envelope"> #<env:Body xmlns="http://rox.sourceforge.net/SOAP/ROX-Filer"> #<PinboardRemove> #<Path>$m</Path> #</PinboardRemove> #</env:Body> #</env:Envelope> #EOF ## Check to see if the entry was removed. #NewNumber=`grep -c ">$m<" /$HOME/Choices/ROX-Filer/PuppyPin` #if [ $OldNumber = $NewNumber ] #then ## If SOAP did not work then remove the icon manually. #RemoveOldRoxIcon "$match" #fi #done #fi MoveToTrash "$m" done FullIcon PlaySoundTrashIt fi fi

To test it's better to have xfe installed but not necessary.

Replace the file AppRun in /usr/local/apps/Trash with this file (Do not forget to save the original AppRun), make it executable.

The script, as it, do not allow restoration or partial deletion of the items in the trashcan. It is necessary to use Rox-Filer or XFE for this.

EDIT : removing an unnecessary step in the script

Caramel
Posts: 320
Joined: Sun Oct 02, 2022 6:25 pm
Location: France
Has thanked: 78 times
Been thanked: 51 times

Re: Comments on the Trash

Post by Caramel »

Small modification for localisation.

The deletion date will be displayed in the local standard (in the summary view)

lines 121 to 133

Code: Select all

  cut -c 2- /tmp/listinfos0 > /tmp/listinfos # delete the initial | of each line
  # create a list with the answer at the question "is it a directory" for each item in the trashcan
  ls -Al /root/.local/share/Trash/files/ | cut -c 1 | sed s/-/no/g | sed s/d/yes/g | awk ' NR > 1 { printf $0"|\n" }' > /tmp/listtestdirectory
  # create a list with the full size of each item
/tmp/listnewnamesfiles
  ls -A /root/.local/share/Trash/files/ | while read line; do du -sbh "/root/.local/share/Trash/files/$line" >> /tmp/listnewnamesfiles; done
  cat /tmp/listnewnamesfiles | awk '{ printf $1"|\n" }' > /tmp/listsizes
  # create a list of all the items (with their names in the trashcan that could different from their original names. For avoid collisions a number could have be added)
  ls -A /root/.local/share/Trash/files/ > /tmp/listnames
  
  # create a file that lists all items with informations (original path, deletion date, Directory or not, size, name in trashcan)
/tmp/listtrashitems
  paste /tmp/listinfos /tmp/listtestdirectory /tmp/listsizes /tmp/listnames >> /tmp/trashitems

replaced by

Code: Select all

  cut -c 2- /tmp/listinfos0 > /tmp/listinfos # delete the initial | of each line
  # create the lists with original paths and delention dates of the items
/tmp/listoriginalpaths
/tmp/listdeletiondates
/tmp/listlocaldeletiondates
  cat /tmp/listinfos | awk ' BEGIN {FS="|"} { print $1"|" } ' >> /tmp/listoriginalpaths
  cat /tmp/listinfos | awk ' BEGIN {FS="|"} { print $2 } ' >> /tmp/listdeletiondates
  # convert the delention dates in local dates
  cat /tmp/listdeletiondates | while read line
   do
   EPOCHTIME=$(date "+%s" -d "$line")
   LOCALDATE=$(date -d @$EPOCHTIME)
   echo $LOCALDATE"|" >> /tmp/listlocaldeletiondates
   done
  # create a list with the answer at the question "is it a directory" for each item in the trashcan
  ls -Al /root/.local/share/Trash/files/ | cut -c 1 | sed s/-/$(gettext 'no')/g | sed s/d/$(gettext 'yes')/g | awk ' NR > 1 { printf $0"|\n" }' > /tmp/listtestdirectory
  # create a list with the full size of each item
/tmp/listnewnamesfiles
  ls -A /root/.local/share/Trash/files/ | while read line; do du -sbh "/root/.local/share/Trash/files/$line" >> /tmp/listnewnamesfiles; done
  cat /tmp/listnewnamesfiles | awk '{ printf $1"|\n" }' > /tmp/listsizes
  # create a list of all the items (with their names in the trashcan that could different from their original names. For avoid collisions a number could have be added)
  ls -A /root/.local/share/Trash/files/ > /tmp/listnames
  
  # create a file that lists all items with informations (original path, deletion date, Directory or not, size, name in trashcan)
/tmp/listtrashitems
  paste /tmp/listoriginalpaths /tmp/listdeletiondates /tmp/listtestdirectory /tmp/listsizes /tmp/listnames >> /tmp/trashitems

IMPORTANT EDIT; bug with the code display
The character > at the start of some lines is not displayed. All the lines that seems start with /tmp/list... actually start with a > (start with > /tmp/list...)

Post Reply

Return to “EasyOS”