WallyZ
Posts: 2
Joined: Thu May 09, 2019 12:50 am

tar destroys directories

Thu May 09, 2019 1:05 am

UNIX/Linux noob of over 30 years!!!

But I'm really new to Raspbian!

So how does this happen.

I download the latest SDL2 tar build. I use the desktop archive utility to look inside and the is a executable in /usr/local/bin a couple of libs in /usr/local/lib some include files in /usr/local/include/SDL2. All looks good. All files in the archive have the full path.

Now I want to overwrite the existing FILES that are there so I use this command to extract the files:

# cd /
# sudo tar xvf ~/Downloads/sdl-raspberrypi-3085.tar.xz
#

That was all it took to blow away every file in the /usr/local/bin

So every command after that was missing. Lucky I remember cd and echo are built into the shell.

# cd /usr/local/bin
# echo *
sdl2-config
#

The only file remaining was the file extracted from the archive!

Since when did tar delete and recreate a directory before restoring files to it.

I tested this on an Ubuntu system (not as root though) and it certainly doesn't!

User avatar
rpdom
Posts: 14483
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: tar destroys directories

Thu May 09, 2019 4:26 am

WallyZ wrote:
Thu May 09, 2019 1:05 am
Now I want to overwrite the existing FILES that are there so I use this command to extract the files:

# cd /
# sudo tar xvf ~/Downloads/sdl-raspberrypi-3085.tar.xz
#

That was all it took to blow away every file in the /usr/local/bin

So every command after that was missing. Lucky I remember cd and echo are built into the shell.

# cd /usr/local/bin
# echo *
sdl2-config
#

The only file remaining was the file extracted from the archive!

Since when did tar delete and recreate a directory before restoring files to it.
It doesn't.

/usr/local/bin is usually empty. There are no files to "blow away". Commands, other than the shell built-in ones like "echo", are usually in /bin, /usr/bin, /sbin and /usr/sbin.
What do you have in those directories?

WallyZ
Posts: 2
Joined: Thu May 09, 2019 12:50 am

Re: tar destroys directories

Fri May 10, 2019 2:28 am

rpdom wrote:
Thu May 09, 2019 4:26 am
WallyZ wrote:
Thu May 09, 2019 1:05 am
Now I want to overwrite the existing FILES that are there so I use this command to extract the files:

# cd /
# sudo tar xvf ~/Downloads/sdl-raspberrypi-3085.tar.xz
#

That was all it took to blow away every file in the /usr/local/bin

So every command after that was missing. Lucky I remember cd and echo are built into the shell.

# cd /usr/local/bin
# echo *
sdl2-config
#

The only file remaining was the file extracted from the archive!

Since when did tar delete and recreate a directory before restoring files to it.
It doesn't.

/usr/local/bin is usually empty. There are no files to "blow away". Commands, other than the shell built-in ones like "echo", are usually in /bin, /usr/bin, /sbin and /usr/sbin.
What do you have in those directories?
Was difficult to tell because the instant I executed the tar command I was unable to do anything due to lack of finding any command.

The first command I recall doing after the tar was ls -l /usr/local/bin/sdl*. I wanted to make sure the ownership and permissions were correct. But that didn't work. then I noticed the default icons in the top bar on the desktop had all been replaced by blank icons.

I couldn't even halt or shutdown. I power cycled and attempted to reboot but it didn't get very far. At this stage I hadn't caught on that everything was deleted.

I then took the sd card over to my other Linux system and took a look around.

There was nothing in /usr/bin as well or /usr/lib they were empty. This completely does not make sense to me. I was considering copying all of /usr/bin and /usr/lib from the stretch image but the more I looked around the more was missing.

It was not a great loss as i had only built the system a few days prior. I just copied the /home/pi directory reflashed the SD card and copied it back.

All I can say is tar was the last thing I did.

swampdog
Posts: 199
Joined: Fri Dec 04, 2015 11:22 am

Re: tar destroys directories

Sat May 11, 2019 6:41 pm

UNIX/Linux noob of over 30 years!!!
But I'm really new to Raspbian!
So how does this happen.
..because you're a very naughty veteran linux noob!

Code: Select all

$ tar --numeric-owner -tvJf /wrk/sdl-raspberrypi-3085.tar.xz |head
drwx------ 126/133           0 2019-04-25 22:18 usr/
drwx------ 126/133           0 2019-04-25 22:18 usr/local/
drwx------ 126/133           0 2019-04-25 22:18 usr/local/include/
drwx------ 126/133           0 2019-04-25 22:18 usr/local/include/SDL2/
-rw-r--r-- 126/133        5161 2019-04-25 22:18 usr/local/include/SDL2/SDL_version.h
-rw-r--r-- 126/133       39294 2019-04-25 22:18 usr/local/include/SDL2/SDL_haptic.h
-rw-r--r-- 126/133       12977 2019-04-25 22:18 usr/local/include/SDL2/SDL_thread.h
-rw-r--r-- 126/133       73586 2019-04-25 22:18 usr/local/include/SDL2/SDL_egl.h
-rw-r--r-- 126/133       82593 2019-04-25 22:18 usr/local/include/SDL2/SDL_opengl.h
-rw-r--r-- 126/133        4839 2019-04-25 22:18 usr/local/include/SDL2/SDL_rect.h
Nothing got deleted, just the mode and owner. ;-)

With gnu tar no need to 'cd /' first: "tar -C / -tvJf foo.xz" will do the job (hint: note manpage for -C, its position is important).

swampdog
Posts: 199
Joined: Fri Dec 04, 2015 11:22 am

Re: tar destroys directories

Sat May 11, 2019 7:07 pm

oops!

Realised I forgot to add something then hit [submit].(*)

$sudo -i tar --no-same-owner --no-same-permissions -C / sdl-raspberrypi-3085.tar.xz

..might do the job (so long since I've used them but I suspect 'sudo -i' is important for the umask etc) but this is likely better off done via "sudo su -" to be sure of the context.

I'm waffling. Need sleep!
(*) Like the time I wiped out a box "Do you really want to remove X thousands of files & folders? - [yes | no]".
Nope. Happy with the fact I'd made the correct decision my finger clicked on [yes]. Fortunately it was a windoze server.

Yes. The archive is packaged wrong btw!

User avatar
rpdom
Posts: 14483
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: tar destroys directories

Sat May 11, 2019 8:16 pm

swampdog wrote:
Sat May 11, 2019 7:07 pm
oops!

Realised I forgot to add something then hit [submit].(*)
This is what the "Edit post" button is for. :)
[edit]
If you edit the post before anyone replies to it, it doesn't even show that it has been edited. :-)

Return to “Raspbian”