Skip to content

Instantly share code, notes, and snippets.

@cadwallion
Created December 7, 2011 15:18
Show Gist options
  • Save cadwallion/1443183 to your computer and use it in GitHub Desktop.
Save cadwallion/1443183 to your computer and use it in GitHub Desktop.
Read-only Detection in Ruby for Java Developers
class File
def self.read_only?(file)
s = File.stat(file)
mode = sprintf("%o", s.mode)
if s.owned?
return true if mode[3].to_i == 4
end
if s.grpowned?
return true if mode[4].to_i == 4
end
return true if mode[5].to_i == 4
return false
end
end
class File
def self.read_only?(file)
s = File.stat(file)
mode = sprintf("%o", s.mode)
return true if s.owned? and mode[3] == ?4
return true if s.grpowned? and mode[4] == ?4
mode[5] == ?4
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment