Bug #238

Ruby doesn't respect the Windows read-only flag

Added by jredville (Jim Deville) almost 4 years ago. Updated about 1 year ago.

[ruby-core:17674]
Status:Rejected Start date:07/09/2008
Priority:Normal Due date:
Assignee:usa (Usaku NAKAMURA) % Done:

0%

Category:-
Target version:-
ruby -v:

Description

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.

History

Updated by jredville (Jim Deville) almost 4 years ago

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

Updated by usa (Usaku NAKAMURA) almost 4 years ago

  • Assignee set to usa (Usaku NAKAMURA)
> 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...

Updated by luislavena (Luis Lavena) almost 4 years ago

> 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.

Updated by jredville (Jim Deville) almost 4 years ago

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.

Updated by usa (Usaku NAKAMURA) almost 4 years ago

> 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...

Updated by jredville (Jim Deville) almost 4 years ago

> 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.

Updated by Anonymous almost 4 years ago

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

Updated by mboeh (Matthew Boeh) almost 4 years ago

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 <stdio.h>

  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

Updated by jredville (Jim Deville) almost 4 years ago

Neil and Matthew: Point taken. 

Updated by matz (Yukihiro Matsumoto) almost 4 years ago

  • Status changed from Open to Rejected

Also available in: Atom PDF