4

I'm working on moving the content of a website, which was provided to me in a RAR archive, to a new server.

I'm not exactly sure which flavor of Linux it is; uname -a tells me:

Linux bolt.sonic.net 2.4.37.5 #1 SMP Mon Aug 17 10:15:36 PDT 2009 i686 unknown

and unrar --help tells me:

UNRAR 3.00 freeware      Copyright (c) 1993-2002 Eugene Roshal

I'm not a regular user of unrar, but in my limited prior experience, the simple command unrar x archive.rar has always done the right thing, as far as I can remember.

But when I try to unpack the current archive, the result is a flat-structured directory containing 4500-odd files and directories whose names have backslashes in them where directory-separators should be, e.g.:

drwxr-xr-x    2 yoyodyne user         4096 Jan 18 14:53 yoyodyne
drwxr-xr-x    2 yoyodyne user         4096 Jan 18 14:53 yoyodyne\application
drwxr-xr-x    2 yoyodyne user         4096 Jan 18 14:53 yoyodyne\application\config
-rw-r--r--    1 yoyodyne user         2765 Sep 15  2011 yoyodyne\application\config\database.php
-rw-r--r--    1 yoyodyne user         1152 Sep 15  2011 yoyodyne\application\config\doctypes.php
-rw-r--r--    1 yoyodyne user         1844 Sep 15  2011 yoyodyne\application\config\foreign_chars.php
-rw-r--r--    1 yoyodyne user          513 Sep 15  2011 yoyodyne\application\config\hooks.php
-rw-r--r--    1 yoyodyne user          123 Sep 15  2011 yoyodyne\application\config\index.html
...

I'm at a complete loss to understand what's causing this to happen, or how to get around it. I'm not seeing any obvious options on the unrar command that tell it, for instance, "Hey, I'm on a Linux system", or "Hey, ignore the fact that this archive was created on a Windows system."

(Actually, I don't know whether the archive was created on a Windows system or not. The developer who sent me the archive didn't say, and promptly went on vacation immediately afterwards -- meaning that my chances of getting an answer, or a replacement archive in a different format, are slim.)

For what it's worth, the unrar program seems to understand that the part of the name after the last backslash is the actual filename. The part of the output of unrar l archive.rar corresponding to the partial directory listing above is:

 Name             Size   Packed Ratio  Date   Time     Attr      CRC   Meth Ver
-------------------------------------------------------------------------------
 database.php     2765     1071  38% 15-09-11 10:57   .....A   13CDB2C8 m3g 2.9
 doctypes.php     1152      381  33% 15-09-11 10:57   .....A   F25E706F m3g 2.9
 foreign_chars.php     1844      856  46% 15-09-11 10:57   .....A   12AF75FD m3g 2.9
 hooks.php         513      285  55% 15-09-11 10:57   .....A   4029E30E m3g 2.9
 index.html        123      107  86% 15-09-11 10:57   .....A   E8DFAEB4 m3g 2.9
 ...
 config              0        0   0% 18-01-13 14:53   .D....   00000000 m0  2.0
 ...
 application         0        0   0% 18-01-13 14:53   .D....   00000000 m0  2.0
 ...

So given this, and given that the unrar program is running on a Linux system, why is it creating these crazy filenames? And what can I do about it?

Hennes
  • 65,804
  • 7
  • 115
  • 169

1 Answers1

0

I don't know the solution for unrar itself, but if you can run vidir and if you manage to unpack the archive content as a flat-structured directory, then this is what you may try to convert it to a directory tree:

# cd to the directory
find . | sort | vidir -

This will open your text editor. Use its features to replace every \ with / and save the file without changing its path (it's a temporary file). vidir will move files and directories to their new paths, creating the desired directory tree.

Notes:

  • Fancy characters in filenames are not supported, vidir expects textual input with standard newlines as entry separators (it won't work with find . -print0 or sort -z).
  • I used sort to ensure every line representing a directory precedes its content-to-be. It's important because vidir will create missing directories while moving an object to its new path. Moving the original directory later would generate a name conflict resolvable with ~ suffix, you don't want this. You want to move the directory before its content, hence sort.
  • Set $EDITOR to make vidir use text editor of your choice (e.g. EDITOR=vi vidir).
  • You can try the experimental approach from my other answer to replace characters automatically, without playing in text editor by hand. In your case the command will be:

    find . | sort | EDITOR='sed -i s|\\|/|g' vidir -