Recent

Author Topic: unzipper leaves files with no permissions  (Read 4676 times)

dbannon

  • Hero Member
  • *****
  • Posts: 2786
    • tomboy-ng, a rewrite of the classic Tomboy
unzipper leaves files with no permissions
« on: October 28, 2018, 12:30:38 pm »
I'm using paszlib to zip up and, later, unzip a bunch of file.
On Linux, works fine but on OSX the output files all end up with no permissions, thus cannot be read etc.

I have used the Mac's unzip command on one of the zip archives and its output is exactly as expected, so clear the problem with TUnZipper.  If I manually change the permissions to something sensible, extracted files are fine. Has anyone any thoughts as to why this would be so ? 

I am doing -

Code: Pascal  [Select][+][-]
  1. uses ... zipper...;
  2. ....
  3.     ZipFile := TUnZipper.Create;
  4.     try
  5.         ZipFile.FileName := FullZipName;
  6.         ZipFile.OutputPath := FullDestDir;
  7.         ZipFile.Examine;
  8.         ZipFile.UnZipAllFiles;
  9.     finally
  10.         ZipFile.Free;
  11.     end;      
  12.  
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

Thaddy

  • Hero Member
  • *****
  • Posts: 14197
  • Probably until I exterminate Putin.
Re: unzipper leaves files with no permissions
« Reply #1 on: October 28, 2018, 02:52:04 pm »
Permissions are bound to the system that they are used on. Which means not necessarily the OS but a specific install of that OS.
You often need to provide a script with your install to set the correct permissions and specifically when you are cross-compiling.
What makes it even more complicated is that is also depends if you cross-compile or native compile.
E.g. cross-compiled from windows to linux has no permissions set, because Windows doesn't know linux file permissions and the files are initially only present on the Windows system.
Likewise is the case regarding your question.

Actually that's a good thing!
« Last Edit: October 28, 2018, 02:57:37 pm by Thaddy »
Specialize a type, not a var.

dbannon

  • Hero Member
  • *****
  • Posts: 2786
    • tomboy-ng, a rewrite of the classic Tomboy
Re: unzipper leaves files with no permissions
« Reply #2 on: October 28, 2018, 11:04:13 pm »
No Thaddy, sorry, I did not make myself clear.

The zipping is not part of an install process. In my app, while it is running, I zip up some of its working or data files. For backup purposes. The user can choose to restore one of the zip archives at a later stage.

So, the zip files (also made by paszlib) are made on the Mac and read on the Mac. We could move a zip archive between platforms but that is not whats happening here.

umask is set to a sensible value.
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: unzipper leaves files with no permissions
« Reply #3 on: October 28, 2018, 11:22:31 pm »
I think the problem may be that TZipper/TUnzipper don't save/restore the file permissions. If you have a Linux box you could test by trying to zip some files with non-standard permissions and seeing if they are restored when unzipping.

I don't have time ATM to test it myself, I fear, but it's worth a try.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

dbannon

  • Hero Member
  • *****
  • Posts: 2786
    • tomboy-ng, a rewrite of the classic Tomboy
Re: unzipper leaves files with no permissions
« Reply #4 on: October 28, 2018, 11:34:13 pm »
I used the Mac's (ie os provided) unzip command on one of the zip archives (created using paszlib), it extracted the files retaining permissions. So, its clearly OK in the Zipping process.

But unzipping using paszlib looses all permissions. Problem is in the unzip stage.

Davo

 
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: unzipper leaves files with no permissions
« Reply #5 on: October 29, 2018, 12:04:44 am »
I used the Mac's (ie os provided) unzip command on one of the zip archives (created using paszlib), it extracted the files retaining permissions. So, its clearly OK in the Zipping process.

The thing is that if all files have the same set of permissions it may be the Mac's unzip who is setting them to some default. I'm not well versed in *BSD systems but some other Unix clones do this too (i.e. create files w/out any permissions whatsoever).
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

dbannon

  • Hero Member
  • *****
  • Posts: 2786
    • tomboy-ng, a rewrite of the classic Tomboy
Re: unzipper leaves files with no permissions
« Reply #6 on: October 29, 2018, 01:10:14 am »
OK, thats a good point.

So, I took a Mac created archive over to my Linux box, extracted and permissions were as expected, 664. But they started out on the Mac as 644.

Then, back on the Mac, I set the permissions of the files to be zipped to write all, 666, zipped them, took that archive to the Linux box and unzipped. And, lo and behold, the files were again 664 !

So, it appears the unzip command honours the local umask, not the original permission. Maybe because zip had its origins in the windows world ?

But, for some reason, TUnzipper does not do that permission setting step on Mac. I'll look at applying appropriate permissions after creation but that might be difficult, given I don't have permission to do so .....

 :)

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: unzipper leaves files with no permissions
« Reply #7 on: October 29, 2018, 02:04:54 am »
IMHO, it's a bug. You should add an entry about in the bugtracker. At a minimum files created when unzipping should be u+rw
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

dbannon

  • Hero Member
  • *****
  • Posts: 2786
    • tomboy-ng, a rewrite of the classic Tomboy
Re: unzipper leaves files with no permissions
« Reply #8 on: October 29, 2018, 03:02:53 am »
Yeah, agree  but paszlib has been around for a long time, I cannot be first to find this ??

Right now I am resetting files to 644 after unzipping using fpChmod (needs baseunix) in an {$ifdef darwin} and thats pretty ugly but will get my release out.

When I have some time, I'll trace back through that paszlib code and see whats happening. Sigh ...

Thanks for your assistance.

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

Thaddy

  • Hero Member
  • *****
  • Posts: 14197
  • Probably until I exterminate Putin.
Re: unzipper leaves files with no permissions
« Reply #9 on: October 29, 2018, 07:58:41 am »
I would test with zip and unzip first: what does that do? If that is better, use Tprocess...If it is equal in behavior than it is not a bug.
The man page for the real unzip states that file permissions are not restored except on Unix:
"Dates, times and permissions of stored  directories  are  not  restored except  under  Unix.  (On Windows NT and successors, timestamps are now restored.)"

Obvously this can only be done if it was zipped on Unix in the first place.
If your situation meets both requirements there is a bug. Otherwise it is defined behavior.
« Last Edit: October 29, 2018, 08:06:56 am by Thaddy »
Specialize a type, not a var.

dbannon

  • Hero Member
  • *****
  • Posts: 2786
    • tomboy-ng, a rewrite of the classic Tomboy
Re: unzipper leaves files with no permissions
« Reply #10 on: October 29, 2018, 08:20:51 am »
Thanks Thaddy, the problem applies to files, not directories. I am satisfied that, for example, on linux, files appear to be restored with umask permissions, not the file's original permissions. Thats OK, as long as we know what to expect.

But more of a problem is that on the Mac, files are restored with no permissions !  That  is, no one can read or write them. And that is, I suggest, unexpected !

Yep, could use TProcess but cannot depend on a zip command being available on Windows (or can I ?) so still have to have different code between platforms. Sigh....

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

Thaddy

  • Hero Member
  • *****
  • Posts: 14197
  • Probably until I exterminate Putin.
Re: unzipper leaves files with no permissions
« Reply #11 on: October 29, 2018, 09:39:21 am »
Thanks Thaddy, the problem applies to files, not directories. I am satisfied that, for example, on linux, files appear to be restored with umask permissions, not the file's original permissions. Thats OK, as long as we know what to expect.

But more of a problem is that on the Mac, files are restored with no permissions !  That  is, no one can read or write them. And that is, I suggest, unexpected !

Yep, could use TProcess but cannot depend on a zip command being available on Windows (or can I ?) so still have to have different code between platforms. Sigh....

Davo

On modern Windows, zip handling is built-in the shell and as such accessible from code. Btw above remark from the unzip man also applies to files.
Specialize a type, not a var.

Zittergie

  • Full Member
  • ***
  • Posts: 114
    • XiX Music Player
Re: unzipper leaves files with no permissions
« Reply #12 on: May 10, 2019, 02:41:14 pm »
Hello dbannon,

did you find a solution?

I have the same problem.  I've developed an application that runs on Windows, Linux and MacOS.  I use zipper to make a backup file, and this backupfile should work on all platforms.

If I use unzipper on a backupfile created on Windows or Linux, there is no problem.  But if I unzip a backup file that was created with MacOS I end up with file that have no permission (You can not read or write the file).
So a backup from MacOS can not be used on linux or Windows (with unzipper)
If I however unzip the files manually everything works fine.

So to be clear:

Created on Linux/Windows  -->  Works fine everywhere
Created on MacOS  -->  Only works fine on MacOS, but if unzipped manually (without fpc-unzipper) it also works fine

BTW no fancy stuff is used just plain zip/unzip:

Code: Pascal  [Select][+][-]
  1. UnZipper:=TUnZipper.Create;
  2.   try
  3.     UnZipper.FileName:=FilenameBackup;
  4.     UnZipper.OutputPath:=BewaarMap;
  5.     UnZipper.Examine;
  6.     Unzipper.UnZipAllFiles;
  7.   finally
  8.     Unzipper.Free
  9.   end;
« Last Edit: May 10, 2019, 02:47:46 pm by Zittergie »
Be the difference that makes a difference

dbannon

  • Hero Member
  • *****
  • Posts: 2786
    • tomboy-ng, a rewrite of the classic Tomboy
Re: unzipper leaves files with no permissions
« Reply #13 on: June 15, 2019, 05:05:40 am »
Sorry for the late reply Zittergie, I have been travelling and out of touch.

No good answer I am afraid, all I do is, on the mac, change the permissions to something sensible after unzipping -

 
Code: Pascal  [Select][+][-]
  1.    {$ifdef Darwin}                     // paszlib, on mac, leaves files with no permissions !
  2.     if FindFirst(FullDestDir + '*.note', faAnyFile, Info)=0 then begin
  3.         repeat
  4.             fpChmod(FullDestDir + Info.Name, &644);    // uses baseunix, should we test return value ?
  5.             until FindNext(Info) <> 0;
  6.         end;
  7.     FindClose(Info);
  8.     if FileExists(FullDestDir + 'config' + PathDelim + 'manifest.xml') then
  9.         fpchmod(FullDestDir + 'config' + PathDelim + 'manifest.xml', &644);
  10.     if FileExists(FullDestDir + 'config' + PathDelim + 'tomboy-ng.cfg') then
  11.         fpchmod(FullDestDir + 'config' + PathDelim + 'tomboy-ng.cfg', &644);
  12.     {$endif}          
  13.  
  14.  

David
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

 

TinyPortal © 2005-2018