Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
FileTest#owned?
(::path | ::io file_name) -> bool
File.owned?(object) → true or false
file.c
View on GitHub ↗
static VALUE
rb_file_owned_p(VALUE obj, VALUE fname)
{
struct stat st;
if (rb_stat(fname, &st) < 0) return Qfalse;
return RBOOL(st.st_uid == geteuid());
}
Returns whether the given object represents a filesystem entry or IO object that exists and is owned by the user of the current process:
Example
filepath = 'doc/t.tmp' File.write(filepath, 'foo') File.owned?(filepath) # => true File.delete(filepath) # Clean up. dirpath = 'doc/tmp' Dir.mkdir(dirpath) File.owned?(dirpath) # => true Dir.rmdir(dirpath) # Clean up. File.owned?($stdin) # => true File.owned?('/etc') # => false