PxPlus User Forum

Twitter Twitter Twitter

Author Topic: *tools\unzip not extracting files if read only  (Read 1056 times)

cwellis67

  • Member
  • **
  • Posts: 8
    • View Profile
*tools\unzip not extracting files if read only
« on: December 01, 2021, 04:13:47 PM »
On Windows, I've noticed that the *tools\unzip utility will generate an untrapped error if the file being extracted already exists AND it is read only on the target system. There doesn't seem to be a way around this other than checking to see if the file on the target system is read only, and if it is, change the flag and then try the extract record from the zip file to overwrite it.

There also doesn't seem to be a nice and clean way of determining through PxPlus if a file is read only or not. Currently, I am OPENing the file, then checking the FIN() to see if the OPEN INPUT bit is set. That seems to be the only indicator that the file was Read Only; otherwise, the file is OPENed normally. Is this the best, or only, way to determine programmatically if a file is Read Only or not?

Likewise, changing the flag seems to require using the system call to use the "attrib" command. Is that also correct? There's no exposed Windows objects I assume?

Thanks!


Mike King

  • Diamond Member
  • *****
  • Posts: 3811
  • Mike King
    • View Profile
    • BBSysco Consulting
Re: *tools\unzip not extracting files if read only
« Reply #1 on: December 01, 2021, 04:39:17 PM »
You can test the FIN(channel, "INPUT") to see if a file is opened for INPUT only.  It will return "1" or "0" ("1" if input only)

Due to nature of different operating systems, there is no method to change file permissions. Windows and Linux/Unix deals with permissions differently thus you need custom code based on your target operating system.

As for unzip, if there is a question of read only permission we would suggest you extract to an empty directory to avoid overwriting a file that the user may have specifically set read only to prevent changing the file.


Mike King
President - BBSysco Consulting
eMail: mike.king@bbsysco.com

cwellis67

  • Member
  • **
  • Posts: 8
    • View Profile
Re: *tools\unzip not extracting files if read only
« Reply #2 on: December 02, 2021, 09:46:08 AM »
** If it is important, we are using PxPlus v15.10

The FIN(ch,"INPUT") tells me that it is available for INPUT, but not that it is input ONLY, which would be the case for a Read Only file, right? When I use the FIN(ch, "INPUT") on a file that is NOT read only, it returns a "1" as well. I need to know that a file is set to Read Only or not. I thought I could use the "WRITE Ok" bit returned from checking the mid(FIN(ch),27,2) bytes, but even if the file is NOT read only, the "write ok" bit is still not set, just the OPEN INPUT bit is set.

An example of what I am seeing is this:
With a file ("1.txt") set to read only:
open(1)"1.txt"
? hta(mid(fin(1),27,2))
? fin(1,"Input")
close(1)

0025
1


When the same file is not read only:
open(1)"1.txt"
? hta(mid(fin(1),27,2))
? fin(1,"Input")
close(1)

0005
1
« Last Edit: December 02, 2021, 09:48:21 AM by cwellis67 »

Mike King

  • Diamond Member
  • *****
  • Posts: 3811
  • Mike King
    • View Profile
    • BBSysco Consulting
Re: *tools\unzip not extracting files if read only
« Reply #3 on: December 02, 2021, 11:18:58 AM »
Sorry -- That should have been "OUTPUT" not "INPUT"
Mike King
President - BBSysco Consulting
eMail: mike.king@bbsysco.com