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

  • 1
  • Idea
  • Updated 7 years ago
  • Not Planned
Some plugins can benefit from having the status of the read-only attribute of a file - please add to LrFileUtils.fileAttributes - thanks.
Photo of Rob Cole

Rob Cole

  • 4831 Posts
  • 384 Reply Likes

Posted 7 years ago

  • 1
Photo of john beardsworth

john beardsworth

  • 1095 Posts
  • 257 Reply Likes
Agreed, though there is already an isWritable property.

John
Photo of Rob Cole

Rob Cole

  • 4831 Posts
  • 384 Reply Likes
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