Re: When will os.remove fail?

2017-03-14 Thread eryk sun
On Tue, Mar 14, 2017 at 10:05 PM, Dennis Lee Bieber wrote: > On Wed, 15 Mar 2017 00:07:32 +1100, Chris Angelico > >>Yes, but you can't always control the process that opens them. For >>example, it's annoyingly difficult to update a running executable. >> > I wouldn't be surprised if Windows mmap(

Re: When will os.remove fail?

2017-03-14 Thread eryk sun
On Tue, Mar 14, 2017 at 7:01 PM, Grant Edwards wrote: > > 1. I think I can see the VMS heritage of Windows shining through. That's not surprising considering that VMS and NT have the same architect -- Dave Cutler -- and that I/O system and file systems were design by former DEC programmers that h

Re: When will os.remove fail?

2017-03-14 Thread Erik
On 14/03/17 13:56, Chris Angelico wrote: On Wed, Mar 15, 2017 at 12:30 AM, Jon Ribbens wrote: rm does not ask before deleting. However some Linux distributions take it upon themselves to put "alias rm='rm -i'" in /etc/profile. I have no such alias, but it still prompts. [snip] This is the

Re: When will os.remove fail?

2017-03-14 Thread Chris Angelico
On Wed, Mar 15, 2017 at 5:28 AM, Michael Felt wrote: > Granted, I am a bit behind in the discussion - and I know nothing about how > Windows manages this since DOS 3.3 - there it also called unlink(). > > rm is the command we run. The system call it uses to remove a file is > unlink(). unlink() re

Re: When will os.remove fail?

2017-03-14 Thread Grant Edwards
On 2017-03-13, eryk sun wrote: [An impressive 150-line explanation of file removal on Windows.] Wow. I have two comments: 1. I think I can see the VMS heritage of Windows shining through. 2. You have my condolences regarding whatever it was that required you to know all that... VMS: for

Re: When will os.remove fail?

2017-03-14 Thread Michael Felt
On 13/03/2017 02:51, Steve D'Aprano wrote: On Mon, 13 Mar 2017 05:45 am, Alain Ketterlin wrote: Steve D'Aprano writes: [...] It seems that os.remove on Linux will force the delete even if the file is read-only or unreadable, provided you own the file. Your permissions on the file do not rea

Re: When will os.remove fail?

2017-03-14 Thread eryk sun
On Tue, Mar 14, 2017 at 1:07 PM, Chris Angelico wrote: > On Tue, Mar 14, 2017 at 10:32 PM, Steve D'Aprano > wrote: > >> I take it that you *can* delete open files, but only if the process that >> opens them takes special care to use "delete sharing". Is that correct? > > Yes, but you can't always

Re: When will os.remove fail?

2017-03-14 Thread eryk sun
On Tue, Mar 14, 2017 at 11:32 AM, Steve D'Aprano wrote: > On Mon, 13 Mar 2017 08:47 pm, eryk sun wrote: > >> One hurdle to getting delete access is the sharing mode. If there are >> existing File objects that reference the file, they all have to share >> delete access. Otherwise the open fails wit

Re: When will os.remove fail?

2017-03-14 Thread Jon Ribbens
On 2017-03-14, Lele Gaifax wrote: > Jon Ribbens writes: >>>Otherwise, if a file is unwritable, standard input is a terminal, and >>>the -f or --force option is not given, or the -i or --interac‐ >>>tive=always option is given, rm prompts the user for whether to remove >>>

Re: When will os.remove fail?

2017-03-14 Thread Lele Gaifax
Jon Ribbens writes: >>Otherwise, if a file is unwritable, standard input is a terminal, >> and >>the -f or --force option is not given, or the -i or >> --interac‐ >>tive=always option is given, rm prompts the user for whether to >> remove >>the file.

Re: When will os.remove fail?

2017-03-14 Thread Chris Angelico
On Wed, Mar 15, 2017 at 1:30 AM, Jon Ribbens wrote: > On 2017-03-14, Chris Angelico wrote: >> On Wed, Mar 15, 2017 at 12:30 AM, Jon Ribbens >> wrote: >>> rm does not ask before deleting. However some Linux distributions >>> take it upon themselves to put "alias rm='rm -i'" in /etc/profile. >> >

Re: When will os.remove fail?

2017-03-14 Thread Jon Ribbens
On 2017-03-14, Frank Millman wrote: > If I type 'alias' at the console, it lists current aliases. 'root' shows > exactly what Jon quoted above. 'frank' shows no alias for 'rm'. > > I had a quick look to see what was setting it, but there is nothing in > /etc/profile or in /etc/bashrc. I don't kn

Re: When will os.remove fail?

2017-03-14 Thread Jon Ribbens
On 2017-03-14, Chris Angelico wrote: > On Wed, Mar 15, 2017 at 12:30 AM, Jon Ribbens > wrote: >> rm does not ask before deleting. However some Linux distributions >> take it upon themselves to put "alias rm='rm -i'" in /etc/profile. > > I have no such alias, but it still prompts. I'm think you

Re: When will os.remove fail?

2017-03-14 Thread Frank Millman
"Frank Millman" wrote in message news:oa8uaf$k9e$1...@blaine.gmane.org... On Fedora 22 (and for many previous versions) I have noticed that, if I log in as 'root', it does prompt, but if I log in as an ordinary user, it does not. If I type 'alias' at the console, it lists current aliases. 'r

Re: When will os.remove fail?

2017-03-14 Thread Chris Angelico
On Wed, Mar 15, 2017 at 1:22 AM, Frank Millman wrote: > "Chris Angelico" wrote in message > news:captjjmrim9tjhfolgynujatx_hkvxxq_d8yjpkx8y32qhcz...@mail.gmail.com... > > On Wed, Mar 15, 2017 at 12:30 AM, Jon Ribbens > wrote: (And the rm command won't ask if you say "-f".) >>> >>>

Re: When will os.remove fail?

2017-03-14 Thread Frank Millman
"Chris Angelico" wrote in message news:captjjmrim9tjhfolgynujatx_hkvxxq_d8yjpkx8y32qhcz...@mail.gmail.com... On Wed, Mar 15, 2017 at 12:30 AM, Jon Ribbens wrote: (And the rm command won't ask if you say "-f".) rm does not ask before deleting. However some Linux distributions take it upon

Re: When will os.remove fail?

2017-03-14 Thread Chris Angelico
On Wed, Mar 15, 2017 at 12:30 AM, Jon Ribbens wrote: > On 2017-03-14, Chris Angelico wrote: >>> (The bash rm command will ask you before deleting, but Python's os.remove >>> just removes it.) >> >> (And the rm command won't ask if you say "-f".) > > rm does not ask before deleting. However some L

Re: When will os.remove fail?

2017-03-14 Thread Jon Ribbens
On 2017-03-14, Chris Angelico wrote: >> (The bash rm command will ask you before deleting, but Python's os.remove >> just removes it.) > > (And the rm command won't ask if you say "-f".) rm does not ask before deleting. However some Linux distributions take it upon themselves to put "alias rm='rm

Re: When will os.remove fail?

2017-03-14 Thread Chris Angelico
On Tue, Mar 14, 2017 at 10:32 PM, Steve D'Aprano wrote: > On Mon, 13 Mar 2017 08:47 pm, eryk sun wrote: >> One hurdle to getting delete access is the sharing mode. If there are >> existing File objects that reference the file, they all have to share >> delete access. Otherwise the open fails with

Re: When will os.remove fail?

2017-03-14 Thread Steve D'Aprano
On Mon, 13 Mar 2017 08:47 pm, eryk sun wrote: > On Sun, Mar 12, 2017 at 5:48 PM, Steve D'Aprano > wrote: >> >> Does os.remove work like this under Windows too? > > os.remove calls DeleteFile on Windows. [...] Thanks for the unexpectedly detailed explanation! A few follow-up questions: > One

Re: When will os.remove fail?

2017-03-13 Thread Marko Rauhamaa
eryk sun : > On Sun, Mar 12, 2017 at 5:48 PM, Steve D'Aprano > wrote: >> >> Does os.remove work like this under Windows too? > > os.remove calls DeleteFile on Windows. [...] Fascinating info, Eryk. The difference between file removal in Linux and Windows is a bit like the difference between obj

Re: When will os.remove fail?

2017-03-13 Thread eryk sun
On Sun, Mar 12, 2017 at 5:48 PM, Steve D'Aprano wrote: > > Does os.remove work like this under Windows too? os.remove calls DeleteFile on Windows. This in turn calls NtOpenFile to instantiate a kernel File object that has delete access and return a handle to it. Next it calls NtSetInformationFile

Re: When will os.remove fail?

2017-03-12 Thread Steve D'Aprano
On Mon, 13 Mar 2017 05:45 am, Alain Ketterlin wrote: > Steve D'Aprano writes: [...] >> It seems that os.remove on Linux will force the delete even if the file >> is read-only or unreadable, provided you own the file. > > Your permissions on the file do not really matters. It's all about your > p

Re: When will os.remove fail?

2017-03-12 Thread Alain Ketterlin
Steve D'Aprano writes: > On Linux, if I call os.remove on a file which I own but don't have write > permission on, the file is still deleted: > > > py> f = open('/tmp/no-write', 'w') > py> os.path.exists('/tmp/no-write') > True > py> os.chmod('/tmp/no-write', 0) # Forbid ALL access. > py> os.rem

Re: When will os.remove fail?

2017-03-12 Thread Larry Martell
On Sun, Mar 12, 2017 at 1:48 PM, Steve D'Aprano wrote: > On Linux, if I call os.remove on a file which I own but don't have write > permission on, the file is still deleted: > > > py> f = open('/tmp/no-write', 'w') > py> os.path.exists('/tmp/no-write') > True > py> os.chmod('/tmp/no-write', 0) #

Re: When will os.remove fail?

2017-03-12 Thread Lele Gaifax
Steve D'Aprano writes: > Under what circumstances will os.remove fail to remove a file? > > If you don't own the file and have no write permission, if it is on > read-only media, anything else? I would say that what matter is the permission on the directory containing the file, not on the file i

When will os.remove fail?

2017-03-12 Thread Steve D'Aprano
On Linux, if I call os.remove on a file which I own but don't have write permission on, the file is still deleted: py> f = open('/tmp/no-write', 'w') py> os.path.exists('/tmp/no-write') True py> os.chmod('/tmp/no-write', 0) # Forbid ALL access. py> os.remove('/tmp/no-write') py> os.path.exists('