Project

General

Profile

Bug #238

Ruby doesn't respect the Windows read-only flag

Added by jredville (Jim Deville) about 11 years ago. Updated about 8 years ago.

Status:
Rejected
Priority:
Normal
Target version:
-
ruby -v:
[ruby-core:17674]

Description

=begin
If you create a file on Windows, attrib +r the file, to give it read-only permissions, and then run Ruby 1.8 or 1.9 and do a Dir.delete on that file, Ruby will delete the file. It should probably throw a SystemCallError to match other platforms.

This has been tested on Vista SP1 with Ruby 1.8 and 1.9.
=end

History

#1

Updated by jredville (Jim Deville) about 11 years ago

=begin
Also applies to Dir.mkdir, which allows making a directory when the parent directory has read-only permissions
=end

#2

Updated by usa (Usaku NAKAMURA) about 11 years ago

  • Assignee set to usa (Usaku NAKAMURA)

=begin

If you create a file on Windows, attrib +r the file, to give it read-only permissions, and then run Ruby 1.8 or 1.9 and do a Dir.delete on that file, Ruby will delete the file. It should probably throw a SystemCallError to match other platforms.

This issue is rejected because I don't know other platform which cannot delete read-only file.
If you know, tell me please.

Also applies to Dir.mkdir, which allows making a directory when the parent directory has read-only permissions

hmm...

=end

#3

Updated by luislavena (Luis Lavena) about 11 years ago

=begin

Also applies to Dir.mkdir, which allows making a directory when the parent directory has read-only permissions

Agree with Mr. Nakamura on the "hmm"..

D:\Users\Luis>cd Desktop
D:\Users\Luis\Desktop>mkdir foo
D:\Users\Luis\Desktop>attrib +r foo
D:\Users\Luis\Desktop>cd foo
D:\Users\Luis\Desktop\foo>copy con x
Hello!
Z
1 file(s) copied.

It doesn't matter if the parent folder is readonly. I have exposed theses issues on "RubySpec forum":http://groups.google.com/group/rubyspec/browse_thread/thread/2e2b21b73aca5fcc# a long time ago, but anyway, file/directory attributes has nothing to do with file/directory permissions.

=end

#4

Updated by jredville (Jim Deville) about 11 years ago

=begin
I'm going based on the standard behavior of the shell:

  • C:\temp » mkdir foo
  • C:\temp » attrib +r foo
  • C:\temp » rm foo Remove-Item : Cannot remove item C:\temp\foo: Not Enough permission to perform operation. At line:1 char:3
  • rm <<<< foo
  • C:\temp »

Bash on OS X is similar, failing with a prompt instead of full failure.

I'll agree with the reject on the Dir.mkdir behavior.
=end

#5

Updated by usa (Usaku NAKAMURA) about 11 years ago

=begin

I'm going based on the standard behavior of the shell:
(snip)
Bash on OS X is similar, failing with a prompt instead of full failure.

This is ruby, not shell :)

If you think it's wrong that ruby can remove read-only file on every platforms, it opens to dispute (and it's not my -- windows port mainterner's issue but matz's and others').
If you assume only Windows to be a problem, it is not accepted.

BTW, Dir.mkdir's behaviour is not same as other platforms.
So I only said "hmm...".
I'm thinking that does changing this behaviour correspond to the work cost or not...
=end

#6

Updated by jredville (Jim Deville) about 11 years ago

=begin

This is ruby, not shell :)

Agreed, but I don't think you should be able to circumvent permissions by going into Ruby.

If you think it's wrong that ruby can remove read-only file on every platforms, it opens to dispute (and it's not my -- windows port mainterner's issue but matz's and others').

I'm up for disputing it. Especially considering the following:

I was wrong on what was here before, i need to explore more before I respond to this and decide whether to dispute it or accept it.

For Dir.mkdir, I'd like to see it act the same on all platforms, but I understand that it's a cost.
=end

#7

Updated by Anonymous about 11 years ago

=begin
Jim Deville wrote:

Issue #238 has been updated by Jim Deville.

This is ruby, not shell :)

Agreed, but I don't think you should be able to circumvent
permissions by going into Ruby.

It seems to me the proper fix is in the OS layer, which is what is
allowing Ruby to do it. If Ruby is 'fixed' this way, you'll still have
to 'fix' every other programming language around. The 'problem' is
going to be there until then.

--
Neil Stevens - neil@hakubi.us

If you're seeing shades of gray, it's because you're not
looking close enough to see the black and white dots.

Attachment: signature.asc
=end

#8

Updated by mboeh (Matthew Boeh) about 11 years ago

=begin
Ruby shouldn't place any arbitrary restrictions on file manipulation that aren't enforced by the C standard library, and neither Windows nor Unix forbid deleting write-protected files:

% cat my-rm.c
#include

int main(int argc, char *argv[])
{
int i;
for (i = 0; i < argc; i++)
remove(argv[i]);
return 0;
}
% gcc my-rm.c -o my-rm
% touch handsoff; chmod a-rwx handsoff
% ./my-rm handsoff
% ls handsoff
ls: handsoff: No such file or directory

It's not circumventing permissions -- rm prompting you before deleting a write-protected file is a courtesy for interactive users, and it doesn't occur otherwise:

% touch handsoff; chmod a-rwx handsoff
% rm handsoff
rm: remove write-protected regular empty file `handsoff'? n
% rm handsoff </dev/null
% ls handsoff
ls: handsoff: No such file or directory
=end

#9

Updated by jredville (Jim Deville) about 11 years ago

=begin
Neil and Matthew: Point taken.
=end

#10

Updated by matz (Yukihiro Matsumoto) about 11 years ago

  • Status changed from Open to Rejected

=begin

=end

Also available in: Atom PDF