Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Sun 21 Dec 2014, 01:47
All times are UTC - 4
 Forum index » House Training » Users ( For the regulars )
Solved - Modify Trash to work with spaces in path or name?
Moderators: Flash, Ian, JohnMurga
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [12 Posts]  
Author Message
disciple

Joined: 20 May 2006
Posts: 6464
Location: Auckland, New Zealand

PostPosted: Sat 18 Aug 2007, 05:43    Post subject:  Solved - Modify Trash to work with spaces in path or name?  

Solved - everything seems to work now. I've updated the code here.
This is an update to the Trash ROXapp so that it will work with files that have spaces in their name or path. Please test.
I'll also do a version that shows you an item in the trash when you click on it, instead of offering to restore it, and that has new entries on the context menu to delete the item, and to view the item.---Edit - this new version is in the next post---

--------------------------
Original post
I'm trying to modify the Trash ROXapp so that it will work with files that have spaces in their name or path (This is one thing that really annoys me in Puppy, and I think it would be a great improvement for newbies). It almost all works, but when I try to restore an item with spaces in its name (it is OK with spaces in the path) I get something like this:
Code:
mv: cannot stat `/root/.Trash/2 3-3565/1': No such file or directory

I can't figure out where the /1 is coming from - I could just strip it off, as it always seems to be /1, but that doesn't seem very proper. I don't really know Bash, and I'm not much of a programmer, so can anyone fix the code please?
-------------------------

We should probably also add a "delete this item" feature, as at the moment if a user goes into the trash and decides the want to delete the only item in there, they're likely to delete it the way you normally delete things, rather than emptying the trash, in which case the trash icon does not get changed to the empty one.

I've attached a .pet below, or here is the [updated] code:
/usr/local/apps/Trash/AppRun:
Code:
#!/bin/bash
# July 10, 2005 - Dan Van Wormer - Puppy Linux

# Create the >Trash directory if it does not already exist.
[ -d /root/.Trash ] || mkdir /root/.Trash

# Determine the path to this application.
APPDIR=`dirname "$0"`
cd "$APPDIR"
APPDIR="`pwd`"

# Play the trash sound
function PlaySound
{

# See if /dev/dsp is in use. If it is then do not play the sound file.
fuser /dev/dsp
if [ $? -eq 0 ];then #=0 if found.
 exit
else
 play $APPDIR/systemmsg.wav
fi
exit

}

function EmptyIcon
{

cp -f "$APPDIR/trashcan_empty.png" "$APPDIR/.DirIcon"
cd ${HOME}
rox -x $APPDIR

}

function FullIcon
{

cp -f "$APPDIR/trashcan_full.png" "$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 a directory for the trashed item.
mkdir "/root/.Trash/$FileName-$$"

# move the item to the Trash directory.
mv "$m" "/root/.Trash/$FileName-$$"

# Copy the icon for the trashed item.
cp -f "$APPDIR/template/trash.png" "/root/.Trash/$FileName-$$/.DirIcon"

# Copy the AppInfo file over.
cp -f "$APPDIR/template/AppInfo.xml" "/root/.Trash/$FileName-$$/AppInfo.xml"

# Write the new AppRun file with.
gawk -v var="PATH" -v name="$m" -v trash="$APPDIR" '{sub(var, name)}
{sub("TRASH", trash)}
{sub("TRASH", trash); print}' $APPDIR/template/temp-AppRun > "/root/.Trash/$FileName-$$/AppRun"

# Make it executable.
chmod 777 "/root/.Trash/$FileName-$$/AppRun"

}

function RemoveOldRoxIcon
{

while grep ">$m<" /root/Choices/ROX-Filer/PuppyPin
 do


  number=`grep -m 1 ">$m<" /root/Choices/ROX-Filer/PuppyPin`

  # Write the new PuppyPin file with the trashed item removed.
  gawk -v var="$number" '{sub(var, ""); print}' /root/Choices/ROX-Filer/PuppyPin > /root/Choices/ROX-Filer/PuppyPin1

  # Rename the new PuppyPin file
  mv /root/Choices/ROX-Filer/PuppyPin1 /root/Choices/ROX-Filer/PuppyPin

  # Restart the pinboard.
  rox -p /root/Choices/ROX-Filer/PuppyPin

done

}

# If they chose the "Look in the Trash" option.
if [ "$1" = "-look" ]
then

 exec rox /root/.Trash

# If they chose the "Empty the Trash" option.
elif [ "$1" = "-empty" ]
then

 # See what is in the trash.
 stuff=`ls /root/.Trash`

 # Write the confirmation message.
 MSG=`which gxmessage` || MSG=xmessage
 $MSG -buttons "Delete:21,Cancel" -center -geometry 300x300 -title    "Confirm Delete" "$stuff"

  # If they chose to cancel.
  [ $? -eq 21 ] || exit

  # If they chose to delete.
  rm -r /root/.Trash/*

 EmptyIcon

 PlaySound

# If they chose to "Quickly Empty the Trash".
elif [ "$1" = "-empty-quick" ]
then

 rm -r /root/.Trash/*

 EmptyIcon

 PlaySound

else

 # Check to see if they clicked on the application or sent a file or directory to be deleted.
 test -sd "$@"
 if [ "$?" = "0" ]
 then

  # If they just clicked on the icon.
  exec rox /root/.Trash

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" -center -geometry 550x90 -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

 fi

 match=`grep ">$m<" /root/Choices/ROX-Filer/PuppyPin`

 # Test $match to see if the item had a link to it on the pinboard.
 test "$match"
 if [ "$?" = "0" ]
 then

  # Write the confirmation message.
  MSG=`which gxmessage` || MSG=xmessage
  $MSG -buttons "Yes:21,No" -center -geometry 560x90 -title    "Confirm Action" "There is one or more Desktop shortcuts pointing to $m
This will move the original item to the Trash and remove the shortcut(s) from the Desktop.
Do you want to continue?"

  # If they chose to cancel.
  [ $? -eq 21 ] || exit

 while check=`grep ">$m<" /root/Choices/ROX-Filer/PuppyPin`
 do

  OldNumber=`grep -c ">$m<" /root/Choices/ROX-Filer/PuppyPin`

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<" /root/Choices/ROX-Filer/PuppyPin`
if [ $OldNumber = $NewNumber ]
then

# If SOAP did not work then remove the icon manualy.
RemoveOldRoxIcon "$match"

fi
done

fi

MoveToTrash "$m"

done

FullIcon

PlaySound

fi

fi

fi



/usr/local/apps/Trash/template/temp-AppRun:
Code:
#!/bin/bash
# March 26, 2006 - Dan Van Wormer - Puppy Linux

# Determine the path to this application.
APPDIR=`dirname "$0"`
cd "$APPDIR"
APPDIR="`pwd`"

# 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
}

# Get the name of the item in the Trash.
getFileName "PATH"

function RestoreItem
{

# Restore the item.
mv "$APPDIR/$FileName" "PATH"

# See what is in the trash.
stuff=`ls /root/.Trash`

getFileName "$APPDIR"

if [ "$FileName" = "$stuff" ]
then

cp -f "TRASH/trashcan_empty.png" "TRASH/.DirIcon"

rox -x TRASH

fi

# Delete this file and directory.
rm -fr "$APPDIR"

}

# If they chose the "Restore" option.
if [ "$1" = "-restore" ]
then

# See if there is already a file or folder of the same name in the same location.
if [ -e "PATH" ]
then

MSG=`which gxmessage` || MSG=xmessage
$MSG -buttons "Yes:21,No" -center -geometry 550x90 -title    "Error" "An item named PATH already exists.
Do you want to overwite it?"

# If they chose to cancel.
[ $? -eq 21 ] || exit

fi

# Restore the item.
RestoreItem

else

# Check to see if they clicked on the application or dropped a file or directory on the icon.
test -sd "$@"
if [ "$?" = "0" ]
then

# If they just clicked on the icon.

# Write the confirmation message.
MSG=`which gxmessage` || MSG=xmessage
$MSG -buttons "Yes:21,No" -center -geometry 550x90 -title    "Confirm Action" "Do you want to restore the item PATH?"

# If they chose to cancel.
[ $? -eq 21 ] || exit

# See if there is already a file or folder of the same name in the same location.
if [ -e "PATH" ]
then

MSG=`which gxmessage` || MSG=xmessage
$MSG -buttons "Yes:21,No" -center -geometry 550x90 -title    "Error" "An item named PATH already exists.
Do you want to overwite it?"

# If they chose to cancel.
[ $? -eq 21 ] || exit

fi

# Restore the item.
RestoreItem

# If they chose the see-path option.
elif [ "$1" = "-see-path" ]
then

# Write the message.
MSG=`which gxmessage` || MSG=xmessage
$MSG -buttons "Okay" -center -geometry 360x90 -title    "Original File Location" "PATH"

else

# If they dropped something to the icon.

# Write the error message.
MSG=`which gxmessage` || MSG=xmessage
$MSG -buttons "Okay" -center -geometry 360x90 -title    "Error" "You can not drop items onto things that are in the Trash."

fi

fi
Trash4spaces.pet
Description 
pet

 Download 
Filename  Trash4spaces.pet 
Filesize  2.54 KB 
Downloaded  678 Time(s) 

Last edited by disciple on Sun 19 Aug 2007, 04:36; edited 1 time in total
Back to top
View user's profile Send private message 
disciple

Joined: 20 May 2006
Posts: 6464
Location: Auckland, New Zealand

PostPosted: Sun 19 Aug 2007, 04:35    Post subject:  

New version as anticipated above:
Works with spaces in filename or path of course.
Opens a trashed item if you click on it, instead of offering to restore it.
Additional context menu options, "Permanently Delete Item" and "Open Item".

BTW. Nathan has modified the original Trash for a multi-user environment, and has some other interesting plans for new features.

----------------------------
Wait a minute - I'll just go and test in a Puppy with the new Rox.
---------------------------
Yes, good, it seems to all work great Smile Smile
Trash4spacesplus.pet
Description  The version below is better :)
pet

 Download 
Filename  Trash4spacesplus.pet 
Filesize  2.92 KB 
Downloaded  681 Time(s) 

Last edited by disciple on Thu 23 Aug 2007, 01:00; edited 1 time in total
Back to top
View user's profile Send private message 
BarryK
Puppy Master


Joined: 09 May 2005
Posts: 7100
Location: Perth, Western Australia

PostPosted: Sun 19 Aug 2007, 05:40    Post subject:  

Great! I've downloaded it.
Back to top
View user's profile Send private message Visit poster's website 
disciple

Joined: 20 May 2006
Posts: 6464
Location: Auckland, New Zealand

PostPosted: Sun 19 Aug 2007, 22:15    Post subject:  

Here's another version, just with an added function to "View item", that opens the appdir in a new window. ---You might not want it with the ROX menu structure in Puppy - I'm using Grafpup 104 long term, and it's much more convenient than searching through the menu for the "look inside" option---Edit-Nonsense---the menu structure is identical---

The "open with" menu is so important in Puppy that it would be quite good to have an "open item with" feature, but that's just getting too complicated for me, so this is the next best thing.
Trash4spacesplus.pet
Description  EDIT - additional "fi"s now removed - as spotted by Dougal
pet

 Download 
Filename  Trash4spacesplus.pet 
Filesize  2.94 KB 
Downloaded  667 Time(s) 

Last edited by disciple on Thu 23 Aug 2007, 00:57; edited 6 times in total
Back to top
View user's profile Send private message 
Dougal


Joined: 19 Oct 2005
Posts: 2505
Location: Hell more grotesque than any medieval woodcut

PostPosted: Mon 20 Aug 2007, 08:38    Post subject:  

You seemed to have an extra "fi" at the end of each of the scripts in the last version (haven't checked the new one yet).
_________________
What's the ugliest part of your body?
Some say your nose
Some say your toes
But I think it's your mind
Back to top
View user's profile Send private message 
disciple

Joined: 20 May 2006
Posts: 6464
Location: Auckland, New Zealand

PostPosted: Mon 20 Aug 2007, 23:38    Post subject:  

Ah - you are right, but that was not me. It was there before I touched them. I guess someone could have removed them in recent Puppies though - I didn't actually check if the trash is exactly the same in them, just looked, and everything claimed to be the same version, so I assumed it was (I did check that spaces didn't work though - that's why I looked to see if there was a new version).

I've just noticed that strange things happen if you restore a file and tell it to overwrite a directory with the same name, or vice versa. I doubt that my changes have caused it, but I don't have time to check it out at the moment.

I don't know why I thought the menu structure was different in ROX now - it is exactly the same, so I think it would be good to use the third version. It just seems a bit more user friendly.
Back to top
View user's profile Send private message 
Dougal


Joined: 19 Oct 2005
Posts: 2505
Location: Hell more grotesque than any medieval woodcut

PostPosted: Tue 21 Aug 2007, 09:09    Post subject:  

disciple wrote:
Ah - you are right, but that was not me. It was there before I touched them.

I'm not sure... I think when you added the extra options you combined a couple of "if"s (the first being the "test -sd" one).

_________________
What's the ugliest part of your body?
Some say your nose
Some say your toes
But I think it's your mind
Back to top
View user's profile Send private message 
disciple

Joined: 20 May 2006
Posts: 6464
Location: Auckland, New Zealand

PostPosted: Thu 23 Aug 2007, 00:53    Post subject:  

Hey, you're right - I did it with temp-AppRun, and it was already there in AppRun. I'll replace the last download with a fixed version now, but it didn't seem to cause any harm.
Back to top
View user's profile Send private message 
disciple

Joined: 20 May 2006
Posts: 6464
Location: Auckland, New Zealand

PostPosted: Sun 26 Aug 2007, 22:21    Post subject:  

We should probably add an additional check when the user restores a file, for either the file being restored or the file being overwritten being a directory, in which case I don't know - rename one of them? Prevent the file being restored?
I think what happens at the moment is if either of them is a directory, you just lose whatever you're trying to restore, unless e.g. I'm restoring a file named "ted" and where it should be restored to there is an existing directory named "ted", without a file or directory named "ted" inside it, in which case the file gets restored into the folder.

We should probably either just give a warning to change the name of something, and refuse to restore the item, or first remove the item to be overwritten, and then restore the item to be restored.

EDIT - Maybe it would even be best to trash the file that would be overwritten.
Back to top
View user's profile Send private message 
disciple

Joined: 20 May 2006
Posts: 6464
Location: Auckland, New Zealand

PostPosted: Sun 26 Aug 2007, 23:48    Post subject:  

OK, if you restore an item, and choose to overwrite something with the same name, this version will send the offending item to the trash first, so it should now be completely safe to restore items.

I am now definitely finished with the Trash Smile
Trash4spacesplus.pet
Description 
pet

 Download 
Filename  Trash4spacesplus.pet 
Filesize  2.97 KB 
Downloaded  698 Time(s) 
Back to top
View user's profile Send private message 
dvw86


Joined: 04 May 2005
Posts: 636
Location: Washington State

PostPosted: Thu 13 Sep 2007, 11:54    Post subject:  

Wow, this is great. I've been a little busy with my new job, house, and all. If I had known you were working on the Trash, I would have helped out. I've just been reading Barry's new page and haven't had much time to spend on the forum. These are all things I was thinking of improving on. The other thing I was thinking of doing was re-writing it in murgaLua. Basically I wanted to eliminate xmessage and give it a much better look. Good job though.
Dan
Back to top
View user's profile Send private message 
disciple

Joined: 20 May 2006
Posts: 6464
Location: Auckland, New Zealand

PostPosted: Sun 14 Oct 2007, 01:29    Post subject:  

OK - I just noticed another problem with the current setup - if you trash an AppInfo.xml or AppRun file, then you lose it because it gets replaced by the one generated to operate the roxapp for the trashed item. If you don't follow me, try it and see what happens.

I think the simplest fix for this would be to change the trash so that instead of putting the trashed item directly in the roxapp, it gets put in a folder with a fixed name - e.g. if I trash a file called 2007-September.txt, instead of getting put in ~/.Trash/2007-September.txt-6926/ it will now get put in ~/.Trash/2007-September.txt-6926/trashed-item/

This should be fairly straightforward, but I think there are a couple of shortcuts we've used in the code that will need to be replaced by some more advanced script that I'd need to research as I know very little BASH. I don't really have any time to do this right now, so if anyone else wants to, feel free.

dvw86 - if it was re-done in murgaLua, would it still be really fast?

If anybody does do anything with it, they might want to also re-look at what would be the best way to handle overwritten items when restoring. I like what I did, but it will cause a problem if you restore something and overwrite a really big item that is on a different partition (you might run out of space in your pup_save when moving the item that is being overwritten to the Trash).
Also, if you keep it my way, I don't think I changed the message to indicate that it is being Trashed, rather than simply overwritten.
------------------------------
BTW if anyone reads this and is concerned about backward compatibility, don't worry - because of the way it works, any updates to the trash app only affect new trashed items, and old ones behave the same way they did when they were trashed.
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [12 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » House Training » Users ( For the regulars )
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1123s ][ Queries: 13 (0.0070s) ][ GZIP on ]