Tiny Core Linux

Tiny Core Base => TCB Talk => Topic started by: GNUser on February 24, 2020, 10:49:11 AM

Title: patch for filetool.sh to "start fresh" before restoring
Post by: GNUser on February 24, 2020, 10:49:11 AM
curaga and juanito,

Some of my configuration directories restored from  mydata.tgz  quickly accumulate extraneous files while the system is running (~/.mozilla and ~/.thunderbird are notorious in this regard).

Because of how  tar  works, running  filetool.sh -r  does not get rid of the extraneous files. Therefore, if I want to restore my configuration directories to their pristine state (as found in mydata.tgz) after the system has been running for a while, I have to manually delete a bunch of directories and only then run  filetool.sh -r  . This is inconvenient.

Therefore, I created a patch for /usr/bin/filetool.sh (see attached) that adds a -z flag to delete ("zero out") all items listed in /opt/.filetool.lst. Now running  filetool.sh -zr  does exactly what I need.

I hope the patch is useful.

    [EDIT]: Patch removed. Safer patches are attached in later posts.  Rich
Title: Re: patch for filetool.sh to "start fresh" before restoring
Post by: Rich on February 24, 2020, 10:58:15 AM
Hi GNUser
You don't use a persistent  home  directory?
Title: Re: patch for filetool.sh to "start fresh" before restoring
Post by: GNUser on February 24, 2020, 10:59:06 AM
No. My /opt is persistent, but not /home.
I dislike the accumulation of files whose function is unknown to me. Call me a clean freak ;D
Title: Re: patch for filetool.sh to "start fresh" before restoring
Post by: Rich on February 24, 2020, 11:02:02 AM
Hi GNUser
You do know there is also an  /opt/.xfiletool.lst  for files and subdirectories you want to exclude from your backup.
Title: Re: patch for filetool.sh to "start fresh" before restoring
Post by: GNUser on February 24, 2020, 11:04:39 AM
I know, Rich. Thank you.
I prefer to include only what I know I want (rather than exclude what I know I don't want). It keeps things as neat and tiny as possible.
Title: Re: patch for filetool.sh to "start fresh" before restoring
Post by: Rich on February 24, 2020, 11:36:05 AM
Hi GNUser
So if I understand this patch correctly, if someone executes:
Code: [Select]
filetool.sh -zIt will read the list of all the files/directories they care about and then delete them.

If that's the case, I would strongly recommend against that patch, at least in its current state. It's too easy for someone to shoot
themselves in the foot.
Title: Re: patch for filetool.sh to "start fresh" before restoring
Post by: GNUser on February 24, 2020, 11:41:32 AM
...will read the list of all the files/directories they care about and then delete them.
That's correct. I guess it is a dangerous patch as currently written.

The operation is not dangerous when -z is combined with -r
I'll rework it and submit a safer patch.
Title: Re: patch for filetool.sh to "start fresh" before restoring
Post by: GNUser on February 24, 2020, 11:52:02 AM
Here you go. Now -z can only be used if combined with -r
Title: Re: patch for filetool.sh to "start fresh" before restoring
Post by: GNUser on February 24, 2020, 11:55:07 AM
Patch with better placement of the safety check is attached.
Title: Re: patch for filetool.sh to "start fresh" before restoring
Post by: Rich on February 24, 2020, 12:08:05 PM
Hi GNUser
Since it tests for an illegal condition, I would change this:
Code: [Select]
+if [ "$ZERO" ] && [ ! "$RESTORE" ]; then
+  echo "-z should only be used with -r"
+fi
+
To that:
Code: [Select]
+if [ "$ZERO" ] && [ ! "$RESTORE" ]; then
+  echo "-z should only be used with -r"
+  exit 3
+fi
+

I will remove the patch you attached in your original post.
Title: Re: patch for filetool.sh to "start fresh" before restoring
Post by: GNUser on February 24, 2020, 12:12:51 PM
Since it tests for an illegal condition...
Good idea. Updated patch attached.

I will remove the patch you attached in your original post.
Thank you. Best not to have the dangerous version of the patch lying around.
Title: Re: patch for filetool.sh to "start fresh" before restoring
Post by: GNUser on February 24, 2020, 12:20:45 PM
Maybe too few users would have any use for the  -z  option? If so, feel free to ignore the patch.

It would be easy enough for the few users who might need this to use a shell script (cleanup followed by filetool.sh -r) instead.
Title: Re: patch for filetool.sh to "start fresh" before restoring
Post by: Rich on February 24, 2020, 12:32:31 PM
Hi GNUser
Maybe too few users would have any use for the  -z  option? If so, feel free to ignore the patch. ...
I was going to mention that your patch may not get accepted as being too specialized. Using  restore  to do a file system cleanup
on a running system is a new one on me.
Title: Re: patch for filetool.sh to "start fresh" before restoring
Post by: curaga on February 24, 2020, 12:34:59 PM
This is the first time this has come up, and I believe a safer/more obvious way to get the same result is to reboot. So right now I'm not inclined to add the patch.
Title: Re: patch for filetool.sh to "start fresh" before restoring
Post by: GNUser on February 24, 2020, 12:39:56 PM
I figured the patch might be rejected in favor of achieving the same thing (yes, in a safer/more obvious way) with a reboot. Fair enough.

You guys do a great job at keeping TCL tiny and beautiful. Thank you :)
Title: Re: patch for filetool.sh to "start fresh" before restoring
Post by: curaga on February 25, 2020, 02:46:19 AM
Things also don't change that often, making it easy to keep custom patches ;)
Title: Re: patch for filetool.sh to "start fresh" before restoring
Post by: GNUser on February 25, 2020, 03:35:25 PM
Things also don't change that often...
That's one of TCL's many qualities--it is conservative and therefore quite resistant to fads :)