Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2001-09-04
23:10 • Closed ticket [219139ffff]: file delete -force does not work on read-only direct... artifact: cd38f74326 user: vincentdarley
22:57 • Ticket [219139ffff]: 4 changes artifact: 8bd261eff3 user: vincentdarley
22:57 • Add attachment fsfixes2.patch to ticket [219139ffff] artifact: 7a650f91de user: vincentdarley
20:56 • Ticket [219139ffff] file delete -force does not work on read-only directories</i... artifact: ab07cdbbe0 user: vincentdarley
20:54 • Ticket [219139ffff]: 4 changes artifact: f41c8262ae user: dkf
19:57 • Ticket [219139ffff]: 4 changes artifact: 47b7e228b7 user: vincentdarley
19:45 • Ticket [219139ffff]: 4 changes artifact: 503319e7d3 user: dkf
18:25 • Ticket [219139ffff]: 4 changes artifact: f3673f1308 user: vincentdarley
18:21 • Ticket [219139ffff]: 4 changes artifact: 5e67ffe13c user: vincentdarley
16:48 • Ticket [219139ffff]: 4 changes artifact: a6f3770196 user: dkf
16:36 • Ticket [219139ffff]: 4 changes artifact: 72065891e5 user: vincentdarley
16:35 • Ticket [219139ffff]: 4 changes artifact: 168ea5364e user: vincentdarley
2001-09-03
16:31 • Ticket [219139ffff]: 4 changes artifact: 5e5be54e00 user: dkf
2001-09-01
00:11 • Ticket [219139ffff]: 4 changes artifact: 0a65ba6328 user: hobbs
2001-08-31
20:22 • Ticket [219139ffff]: 4 changes artifact: 4a343d6f5e user: vincentdarley
2001-08-24
05:08 • Ticket [219139ffff]: 1 change artifact: 193a0208ea user: andreas_kupries
2000-11-10
20:53 • Ticket [219139ffff]: 4 changes artifact: 717b14567f user: dkf
2000-10-26
05:02 • New ticket [219139ffff]. artifact: 8641aea868 user: nobody

file delete -force does not work on read-only directories

Closed / Fixed219139ffffffffffffffffffffffffffffffffffCreated 26 years agoUpdated 25 years ago
Descriptionplain2000-10-26 05:02:14
OriginalBugID: 668 Bug
Version: 8.0p2
SubmitDate: '1998-07-29'
LastModified: '2000-01-20'
Severity: MED
Status: Assigned
Submitter: stanton
ChangedBy: hobbs
OS: All
OSVersion: NA
Machine: NA
FixedDate: '2000-01-20'
ClosedDate: '2000-10-25'


If a directory is not writable, file delete -force fails on the first file in the directory.



like 'rm -rf readonlydir/', the error should be expected.  The docs
don't mention this, so the docs have been updated for 8.3.0. 
-- 01/20/2000 hobbs
Correction - the intention is that, unlike rm, file delete -force
should delete hell-or-high-water, which means we need to adjust
the perms on a directory before nixing it in the -force case. 
-- 01/20/2000 hobbs
dkfplain2000-11-10 20:53:54
It might not be possible to delete the file in any case e.g. if it exists in a directory to which we have no write access and where we cannot change the permissions on the file.
andreas_kupries Ticket [219139ffff]: 1 change [History diff]2001-08-24 05:08:28
vincentdarleyplain2001-08-31 20:22:11
Logged In: YES 
user_id=32170

Also if 'cwd' is inside the directory, a delete will fail 
(although we could even check for that and do a 'cd [file 
dirname $dir]')

I assume from Jeff's comments that the idea of 'file 
delete -force' is to try everything possible to get rid of 
the file, including moving the cwd, changing permissions 
etc?
hobbsplain2001-09-01 00:11:21
Logged In: YES 
user_id=72656

Yes, the idea would be to attempt other things to actually 
delete the directory.  This was mentioned to me by Scott 
Stanton as the original intention (and thus the bug 
report), but I'm not dead set on it.
dkfplain2001-09-03 16:31:45
Logged In: YES 
user_id=79902

Following on from Vince's comment, things become even more
sticky when the 'cwd' of another process is inside the
directory.  At that point, you're basically stuck.  (I have
no idea if there are networked filesystems that support that
style of directory locking, but if there are you have the
situation where a blocking process might not even be on the
same computer.  But even without that finesse, the point
still holds since you can't change the directory of other
processes underneath their feet...)

Anyway, hell-or-high-water isn't possible.  Best effort
(probably up to about the level of 'rm -rf' I'd guess) is.
vincentdarleyplain2001-09-04 16:35:05
Logged In: YES 
user_id=32170

The changing permisions piece is very easy to implement.  
In 'DoRemoveDirectory' (tclUnixFCmd.c), we must simply add:

    
    if (recursive) {
        /* We should try to change permissions 
         * so this can be deleted */
chmod(path, XXX);
    }
    
could someone enlighten me to what the correct value 
of 'XXX' should be here?
vincentdarleyplain2001-09-04 16:36:12
Logged In: YES 
user_id=32170

It would also be useful to have a new test which currently 
fails on unix, but should pass after add 'chmod' as below --
- any takers?
dkfplain2001-09-04 16:48:21
Logged In: YES 
user_id=79902

I'd guess the permissions to be 0700; don't care about
losing perms for other people as the dir is about to be
nuked anyway.  Though if the delete then fails, we must
restore the perms to what they were before since the failure
might be due to another process owned by another user using
that dir as a working directory and making it fail in that
case is not too good.  I think...

The classic way to test this is (I suppose) to create a
directory with a file in it, change its permissions to
something aggressively unreadable, and then attempt to
delete it.  We can then force an unfixable failure by
putting a subprocess in there (which would also be good for
making sure that the permissions don't end up too screwed in
the case of a failure.)
vincentdarleyplain2001-09-04 18:21:56
File Added - 10356: fsfixes.patch

Logged In: YES 
user_id=32170

Attached patch to fix this and some other problems.  Please 
test on unix (and ideally add a test case...).

Vince.
vincentdarleyplain2001-09-04 18:25:18
File Deleted - 10356: 



File Added - 10357: fsfixes.patch
dkfplain2001-09-04 19:45:30
Logged In: YES 
user_id=79902

It strikes me as odd that we have an open fd for the
temporary file and then we immediately close it only to
reopen it again (as part of copying.)  Wouldn't it be better
to change TclpTempFileName() to pass back both the name of
the file and a (binary read-write) channel with which to
access the file?  One of the faults with using tmpnam() as I
understand it is that you can have an attacker create the
file with some nefarious content in-between getting the
filename (of a non-existing-at-the-time file) and creating
the file.  If changed to produce both channel and filename,
then it is obvious that the name of the function needs to
change as well (to TclpCreateTempFile for example?)
vincentdarleyplain2001-09-04 19:57:24
Logged In: YES 
user_id=32170

I considered doing that, perhaps combining the function 
with the (existing) 'TclpCreateTempFile' which is above.  

I appreciate the comment about 'tmpnam'; the approach in 
the patch does have the benefit that the file actually 
exists (even though we closed it), so I don't think an 
attacker can mess with it.  What happens next is that we 
overwrite the existing file.

All in all I didn't see massive benefits from returning 
both the name and the channel.  While avoiding the 'open-
close-open' behaviour of the current code, in other ways it 
complicates things (the Win/Mac ports must explicitly open 
the temp file, the file handle must be converted to a 
Tcl_Channel in all three platforms, we need to modify the 
shared CrossFilesystemCopy, etc...)

Anyway, I don't feel that strongly about it, so am happy to 
be argued back (!).   Does the patch actually compile and 
pass the tests?
dkfplain2001-09-04 20:54:25
Logged In: YES 
user_id=79902

Patch doesn't even apply cleanly.  (I think only one chunk
out of the whole lot applies at all!)  :^(
vincentdarleyplain2001-09-04 20:56:22
Logged In: YES 
user_id=32170

I assume you converted eols to unix, etc?
vincentdarleyplain2001-09-04 22:57:33
File Deleted - 10357: 



File Added - 10364: fsfixes2.patch
vincentdarleyplain2001-09-04 23:10:04
Logged In: YES 
user_id=32170

This works in latest patch.
Log in (anonymous is fine) to add a comment.

Attachments: