rob_cole_2221866's profile

4.5K Messages

 • 

76.3K Points

Sat, Oct 22, 2011 6:11 AM

Closed

Not planned

Lightroom SDK: LrFileUtils.fileAttributes - include read-only.

Some plugins can benefit from having the status of the read-only attribute of a file - please add to LrFileUtils.fileAttributes - thanks.

1.3K Messages

 • 

22.5K Points

10 y ago

Agreed, though there is already an isWritable property.

John

4.5K Messages

 • 

76.3K Points

Thanks John, I'm not sure how I overlooked that before.

*** As far as I'm concerned this 'Idea' can be deleted as erroneous.
*** As far as I'm concerned this 'Idea' can be deleted as erroneous.
*** As far as I'm concerned this 'Idea' can be deleted as erroneous.

Just for grins, here's the code I've been using:

--- Determine if file is read-only.
--
-- @return true iff read-only.
-- @return error message iff didn't work.
--
function Disk:isReadOnly( path )
if WIN_ENV then
local s, m, c = app:executeCommand( "ATTRIB", nil, { path }, nil, "del" )
if s then
local r = c:find( "%sR%s" )
local f = c:find( path, 1, true )
if f then
if r and r < f then
return true
else
return false
end
else
return nil, "file attributes not found: " .. path
end
else
return nil, m
end
else
local s, m, c = app:executeCommand( "ls", "-l", { path }, nil, "del" )
if s then
if c then
local p1, p2 = c:find( LrPathUtils.leafName( path ), 1, true )
if p1 and p1 > 10 then
-- u g o
-- drwxrwxrwx
-- 1234567890
local u = str:getChar( c, 3 )
local g = str:getChar( c, 6 )
local o = str:getChar( c, 9 )
if u == 'w' or g == 'w' or o == 'w' then -- its writeable by somebody.
return false
else
return true -- not writeable by anybody.
end
else
return nil, "invalid response to ls command (for read-only attributes): " .. str:to( c )
end
else
error( "program failure - no command content returned" )
end
else
return nil, m
end
end
end