* Get Directory Permissions

For users to report plugin bugs and request plugin enhancements; and for authors to test new/new versions of plugins, and to discuss plugin development (in the Programming Technicalities sub-forum). If you want advice on choosing or using a plugin, please ask in General Usage or an appropriate sub-forum.
Post Reply
User avatar
tatewise
Megastar
Posts: 27087
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Get Directory Permissions

Post by tatewise » 01 May 2020 19:36

Does anyone know a way to get the current permissions for a directory/folder in Lua?
I need to know if a directory/folder can be written, i.e. files saved or deleted inside that directory/folder.

There is one constraint ~ the Date modified of the directory/folder must NOT be affected.
So that rules out saving & deleting a temporary file, as it updates the Date modified!

I have looked at the lfs and pl library modules, but neither seem to offer that feature.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

User avatar
Mark1834
Megastar
Posts: 2147
Joined: 27 Oct 2017 19:33
Family Historian: V7
Location: South Cheshire, UK

Re: Get Directory Permissions

Post by Mark1834 » 02 May 2020 07:30

Mike - this looks like it might be relevant (not checked it myself)

https://stackoverflow.com/questions/164 ... ble-in-lua
Mark Draper

User avatar
tatewise
Megastar
Posts: 27087
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Get Directory Permissions

Post by tatewise » 02 May 2020 10:57

Thank you Mike, but firstly that is not talking about file permissions but only file existence.
Sencondly, the LuaFileSystem (lfs) does not provide file/folder permissions, the luaposix library is not available for FH, and access no longer exists. Unless, that is, anyone knows different.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

User avatar
ColeValleyGirl
Megastar
Posts: 4854
Joined: 28 Dec 2005 22:02
Family Historian: V7
Location: Cirencester, Gloucestershire
Contact:

Re: Get Directory Permissions

Post by ColeValleyGirl » 02 May 2020 12:38

lfs.attributes (filepath [, request_name | result_table])
Returns a table with the file attributes corresponding to filepath (or nil followed by an error message and a system-dependent error code in case of error). If the second optional argument is given and is a string, then only the value of the named attribute is returned (this use is equivalent to lfs.attributes(filepath)[request_name], but the table is not created and only one attribute is retrieved from the O.S.). if a table is passed as the second argument, it (result_table) is filled with attributes and returned instead of a new table. The attributes are described as follows; attribute mode is a string, all the others are numbers, and the time related attributes use the same time reference of os.time:
<snip>
permissions
file permissions string
Does this not work on folders then?

User avatar
tatewise
Megastar
Posts: 27087
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Get Directory Permissions

Post by tatewise » 02 May 2020 13:35

No, the lfs provided by require("lfs") in FH Lua does not return the permissions attribute for anything.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

User avatar
Mark1834
Megastar
Posts: 2147
Joined: 27 Oct 2017 19:33
Family Historian: V7
Location: South Cheshire, UK

Re: Get Directory Permissions

Post by Mark1834 » 03 May 2020 08:33

Curious - I think you might have misread the linked page, Mike (or equally I might have misunderstood your question ;) ).

If I run the code snippet in Linux, it behaves exactly as described, with the illustrated table including the default permissions for a newly created test directory (full rwx for owner, read-only for others).

Linux.PNG
Linux.PNG (10.21 KiB) Viewed 6835 times
However, the same code in FH generates a slightly different table for my Charts folder, with the permissions line missing.

W10.PNG
W10.PNG (10.99 KiB) Viewed 6835 times
So LuaFileSystem can return permissions in Linux but not in FH. I don't know if that is a limitation of Windows generally or the Lua version supplied with FH, but file permissions generally seem much more opaque in Windows compared with Linux.
Mark Draper

User avatar
tatewise
Megastar
Posts: 27087
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Get Directory Permissions

Post by tatewise » 03 May 2020 09:40

Yes, it is curious!
The LuaFileSystem Manual mentions many variants and exceptions for Unix and Windows but the permissions attribute appears to be unconditional.
The LuaFileSystem History does not mention permissions being added so presumably has always existed.
Yet the FH version does not support the permissions attribute!
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

User avatar
mjashby
Megastar
Posts: 692
Joined: 23 Oct 2004 10:45
Family Historian: V7
Location: Yorkshire

Re: Get Directory Permissions

Post by mjashby » 03 May 2020 11:12

Mike,

Not sure if the following link to a discussion thread helps or hinders, but seems to provide some explanation the lack of a direct functionality in Lua: https://stackoverflow.com/questions/283 ... -directory

Unfortunately, so far, I'm lacking any significant understanding of Lua scripting, so forgive me if it's of no help.

Mervyn

User avatar
tatewise
Megastar
Posts: 27087
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Get Directory Permissions

Post by tatewise » 03 May 2020 11:58

Thank you Mervyn, but again that just identifies the existence of a directory and NOT its permissions such as Write access.
I know all about what LuaFileSystem (lfs) can and cannot do.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

User avatar
mjashby
Megastar
Posts: 692
Joined: 23 Oct 2004 10:45
Family Historian: V7
Location: Yorkshire

Re: Get Directory Permissions

Post by mjashby » 03 May 2020 15:03

Mike,

I was sure that would be the case, but the thread I linked to seems to confirm that there is no functionality in Lua to get data on Directories directly, so an external function has to be written and called.

Mervyn

User avatar
tatewise
Megastar
Posts: 27087
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Get Directory Permissions

Post by tatewise » 03 May 2020 15:09

Yes, and it is just such an external library function that I am searching for without success.
The LuaFileSystem (lfs) is an external library function that gets tantalisingly close.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

User avatar
ColeValleyGirl
Megastar
Posts: 4854
Joined: 28 Dec 2005 22:02
Family Historian: V7
Location: Cirencester, Gloucestershire
Contact:

Re: Get Directory Permissions

Post by ColeValleyGirl » 03 May 2020 16:09

The code is in the lfs library -- look for perm2string -- it even tests for Windows versus Linux.

I'm going to guess that it's a library version problem. The capability existed at least 5 years ago but wasn't documented then. That code is version 1.8 and 11 days old... I'm going to guess we've got version 1.5 based on the timestamp on my lfs.dll

User avatar
tatewise
Megastar
Posts: 27087
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Get Directory Permissions

Post by tatewise » 03 May 2020 17:03

Thanks Helen. Looks like you are correct. It's the old problem of FH V6 not disclosing which versions of libraries it offers.
Hopefully, FH V7 will offer the latest version of lfs and put me out of my misery :D
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry


User avatar
tatewise
Megastar
Posts: 27087
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Get Directory Permissions

Post by tatewise » 07 May 2020 17:28

Thank you Ron, that may be a possibility.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

User avatar
Ron Melby
Megastar
Posts: 878
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: Get Directory Permissions

Post by Ron Melby » 07 May 2020 21:17

I dont know what it does to last access date. It is distressing that one has to wend thru so many warps and woofs to get permissions, and many other simple but necessary things.

One stupid thing that bothers me, is that when you right click on something ... and it somehow varies, and say you want to open with EditPadLite or some other editor (say its a saved table) there are two possible open with screens that come up, one is quite easy (but you can't be a casual user, you have to stick keys in the registry) to remove the always open with.... the other I can find no way to default to unchecked, even after talking to M$. and of course once you hit the ok, forgetting to uncheck the box, its a horror to unwind.
FH V.6.2.7 Win 10 64 bit

User avatar
Ron Melby
Megastar
Posts: 878
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: Get Directory Permissions

Post by Ron Melby » 07 May 2020 21:47

https://docs.microsoft.com/en-us/archiv ... ermissions there is this, and you are handy with the old Registry......
FH V.6.2.7 Win 10 64 bit

Post Reply