Code::Blocks Forums

User forums => General (but related to Code::Blocks) => Topic started by: thomas on August 09, 2005, 02:36:10 pm

Title: Quite off topic
Post by: thomas on August 09, 2005, 02:36:10 pm
After implementing export with archive generation (to build source releases) into the svn plugin, I encountered a "bug" which I've been struggling all day. Sometimes, it would fail for no obvious reason.
Now I have come to a really weird conclusion: There is no bug at all. Instead, it is as simple as this: tar under Windows (either msys or cygwin) cannot handle pathnames longer than 31 characters.

This sounds so hilarious, it can hardly be true, but it really seems to be the case.

Did anyone else experience that, too, or am I missing something?

Code
D:\desktop>tar -cf D:/Desktop/SomeFolder/a.tar a.txt
tar: Cannot execute remote shell: No such file or directory
tar: D\:/Desktop/SomeFolder/a.tar: Cannot open: Input/Output error
tar: Error is not recoverable: exiting now

D:\desktop>mv SomeFolder SoFo

D:\desktop>tar -cf D:/Desktop/SoFo/a.tar a.txt

D:\desktop>mv SoFo Some

D:\desktop>tar -cf D:/Desktop/Some/a.tar a.txt

D:\desktop>mv Some SomeF

D:\desktop>tar -cf D:/Desktop/SomeF/a.tar a.txt
tar: Cannot execute remote shell: No such file or directory
tar: D\:/Desktop/SomeF/a.tar: Cannot open: Input/Output error
tar: Error is not recoverable: exiting now
Title: Re: Quite off topic
Post by: Profic on August 09, 2005, 04:08:21 pm
Msys shell:
Code
Profic@PROFIC-NBOOK /e/work/web/SDN/recipe-nddocs/cpp
$ tar cf /e/work/web/SDN/recipe-nddocs/cpp/rtfReader.tar rtfReader

Profic@PROFIC-NBOOK /e/work/web/SDN/recipe-nddocs/cpp
$

cmd shell:
Code
E:\work\web\SDN\recipe-nddocs\cpp>c:\devel\msys\bin\tar cf e:\work\web\SDN\recipe-nddocs\cpp\rtfReader.tar rtfReader
/bin/tar: e\:\\work\\web\\SDN\\recipe-nddocs\\cpp\\rtfReader.tar: Cannot open: I/O error
/bin/tar: Error is not recoverable: exiting now

E:\work\web\SDN\recipe-nddocs\cpp>c:\devel\msys\bin\tar cf /e/work/web/SDN/recipe-nddocs/cpp/rtfReader.tar rtfReader

E:\work\web\SDN\recipe-nddocs\cpp>

So, yes, problem is there.
Title: Re: Quite off topic
Post by: thomas on August 09, 2005, 04:37:04 pm
Thanks for the reply :)

So well... that kind of stinks. Considering the "normal" length of file paths in Windows, this effectively makes tar unusable, except if you agree to cd to the respective directory, create the archive there, and copy it to another destination later.

I've changed my code now so that tar writes to wxFileName::CreateTempFileName(). TemFileNames are usually 6-7 characters, so that leaves 24 characters for %TEMPDIR%  :?
After tar has finished, the file is moved to and renamed to what it should have been in the first place. Nasty hack, cannot say I like that. But oh well... it works.
Title: Re: Quite off topic
Post by: takeshimiya on August 09, 2005, 06:26:13 pm
Are you using the latest tar 1.15.1 ?

http://www.gnu.org/software/tar/tar.html
http://directory.fsf.org/tar.html
Title: Re: Quite off topic
Post by: thomas on August 09, 2005, 07:52:10 pm
No, the version that comes with the most recent msys, that's 1.13.25.

Will check out the 1.15.1 version for curiosity, but I assume that most people will have not much more recent versions than the one I use, so I'll have to keep the temp file hack anyway.


EDIT:
Version number hell, again... the msys one is 1.13.19. Cygwin has version 1.13.25.
Title: Re: Quite off topic
Post by: takeshimiya on August 10, 2005, 12:03:29 am
Ok, ok, a simply looking at tar --help I found the cause, tar (in Windows at least) doesn't support a directory parameter to -f.  :D

You must specify always FILES only with -f (--file), not DIRECTORIES.
You must specify the origin DIRECTORY with -C (--directory).

This will do the trick:
Code
D:\desktop\SomeFolder>tar -cf a.tar -C D:/desktop/SomeFolder a.txt

However, it is also bad,

The correct way is enclosing with quotes all directories and files, because the filenames/directories can contain spaces:
Code
D:\desktop\SomeFolder>tar -cf "a.tar" -C "D:/desktop/SomeFolder" "a.txt"

I think that always it's recommended to enclose with quotes the filenames/directories when passing as a parameter to any program.

That's it :)
Title: Re: Quite off topic
Post by: takeshimiya on August 10, 2005, 12:15:59 am
For more information, refer to the help of tar,

ie. the help says that you can do something like this:
Code
example% cd fromdir; tar cf - .| (cd todir; tar xfBp -)

http://www.computerhope.com/unix/utar.htm
http://www.gnu.org/software/tar/manual/html_mono/tar.html
Title: Re: Quite off topic
Post by: thomas on August 10, 2005, 04:59:39 pm
Takeshimiya, this helped a lot, thank you :)
Hard to believe I've been using tar wrong ever since, lol. Funny enough, it works on Linux just the way I expected it to.

It is almost perfect now like this:
  export repo to %SYSTEMTEMP%/SomeTempFolder
  cd to desired location of archive
  tar -cf archivename.tar -C %SYSTEMTEMP%/SomeTempFolder .

The only issue that remains is that tar puts everything into a folder "." inside the tar archive which is a little unpleasing. Luckily, this does not matter much, as the archives unpack fine. Sure one could work around that, but I guess I'll leave it. None of the compression utilities that I have tried seems to have a problem with it.
Title: Re: Quite off topic
Post by: grv575 on August 10, 2005, 08:46:43 pm
Odd, but I guess . is a directory.

Wouldn't

tar -cf archivename.tar -C %SYSTEMTEMP%/SomeTempFolder *

work?
Title: Re: Quite off topic
Post by: thomas on August 11, 2005, 01:03:22 am
Odd, but I guess . is a directory.

Wouldn't

tar -cf archivename.tar -C %SYSTEMTEMP%/SomeTempFolder *

work?
No because * will be expanded to all files in your CWD, not to all files in the directory given with -C.

EDIT: Funnily, that was my first thought, too, but it is obviously wrong if you think about it. Unluckily, tar does no shell expansion of its own, so "*" will not work either - tar will complain "no such file: *".