* Get Directory Permissions
- tatewise
- Megastar
- Posts: 28410
- Joined: 25 May 2010 11:00
- Family Historian: V7
- Location: Torbay, Devon, UK
- Contact:
Get Directory Permissions
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.
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
- Mark1834
- Megastar
- Posts: 2511
- Joined: 27 Oct 2017 19:33
- Family Historian: V7
- Location: South Cheshire, UK
Re: Get Directory Permissions
Mike - this looks like it might be relevant (not checked it myself)
https://stackoverflow.com/questions/164 ... ble-in-lua
https://stackoverflow.com/questions/164 ... ble-in-lua
Mark Draper
- tatewise
- Megastar
- Posts: 28410
- Joined: 25 May 2010 11:00
- Family Historian: V7
- Location: Torbay, Devon, UK
- Contact:
Re: Get Directory Permissions
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.
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
- ColeValleyGirl
- Megastar
- Posts: 5499
- Joined: 28 Dec 2005 22:02
- Family Historian: V7
- Location: Cirencester, Gloucestershire
- Contact:
Re: Get Directory Permissions
Does this not work on folders then?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
Helen Wright
ColeValleyGirl's family history
ColeValleyGirl's family history
- tatewise
- Megastar
- Posts: 28410
- Joined: 25 May 2010 11:00
- Family Historian: V7
- Location: Torbay, Devon, UK
- Contact:
Re: Get Directory Permissions
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
- Mark1834
- Megastar
- Posts: 2511
- Joined: 27 Oct 2017 19:33
- Family Historian: V7
- Location: South Cheshire, UK
Re: Get Directory Permissions
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).
However, the same code in FH generates a slightly different table for my Charts folder, with the permissions line missing.
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.
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).
However, the same code in FH generates a slightly different table for my Charts folder, with the permissions line missing.
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
- tatewise
- Megastar
- Posts: 28410
- Joined: 25 May 2010 11:00
- Family Historian: V7
- Location: Torbay, Devon, UK
- Contact:
Re: Get Directory Permissions
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!
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
Re: Get Directory Permissions
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
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
- tatewise
- Megastar
- Posts: 28410
- Joined: 25 May 2010 11:00
- Family Historian: V7
- Location: Torbay, Devon, UK
- Contact:
Re: Get Directory Permissions
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.
I know all about what LuaFileSystem (lfs) can and cannot do.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
Re: Get Directory Permissions
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
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
- tatewise
- Megastar
- Posts: 28410
- Joined: 25 May 2010 11:00
- Family Historian: V7
- Location: Torbay, Devon, UK
- Contact:
Re: Get Directory Permissions
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.
The LuaFileSystem (lfs) is an external library function that gets tantalisingly close.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
- ColeValleyGirl
- Megastar
- Posts: 5499
- Joined: 28 Dec 2005 22:02
- Family Historian: V7
- Location: Cirencester, Gloucestershire
- Contact:
Re: Get Directory Permissions
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
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
Helen Wright
ColeValleyGirl's family history
ColeValleyGirl's family history
- tatewise
- Megastar
- Posts: 28410
- Joined: 25 May 2010 11:00
- Family Historian: V7
- Location: Torbay, Devon, UK
- Contact:
Re: Get Directory Permissions
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
Hopefully, FH V7 will offer the latest version of lfs and put me out of my misery
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
Re: Get Directory Permissions
wonder if fhShellExecute will help or if you got to go to os.execute
powershell
https://docs.microsoft.com/en-us/powers ... wershell-7
https://docs.microsoft.com/en-us/powers ... wershell-7
get-acl
https://docs.microsoft.com/en-us/powers ... parameters
https://docs.microsoft.com/en-us/powers ... wershell-7
eventually...
https://itconnect.uw.edu/wares/msinf/ot ... dl-syntax/
powershell
https://docs.microsoft.com/en-us/powers ... wershell-7
https://docs.microsoft.com/en-us/powers ... wershell-7
get-acl
https://docs.microsoft.com/en-us/powers ... parameters
https://docs.microsoft.com/en-us/powers ... wershell-7
eventually...
https://itconnect.uw.edu/wares/msinf/ot ... dl-syntax/
FH V.6.2.7 Win 10 64 bit
- tatewise
- Megastar
- Posts: 28410
- Joined: 25 May 2010 11:00
- Family Historian: V7
- Location: Torbay, Devon, UK
- Contact:
Re: Get Directory Permissions
Thank you Ron, that may be a possibility.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
Re: Get Directory Permissions
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.
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
Re: Get Directory Permissions
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