Created
December 7, 2011 15:18
-
-
Save cadwallion/1443183 to your computer and use it in GitHub Desktop.
Read-only Detection in Ruby for Java Developers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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