Overview
| Artifact ID: | 9cd2f84cd91d891947c095161ee71d334b50f50d |
|---|---|
| Ticket: | 2406596fffffffffffffffffffffffffffffffff
file delete reports an error on non-existent file |
| User & Date: | ralfixx on 2008-12-08 14:16:46 |
Changes
- assignee changed to: "vincentdarley"
- cmimetype changed to: "text/plain"
- comment changed to:
[file delete] is documented as: Trying to delete a non-existent file is not considered an error. However, the following code reports an error when run in two simultaneous processes on Linux: #!/bin/sh -- set testfile /tmp/testfile while {1} { # create the testfile, ignore any errors catch {close [open $testfile w]} # call file delete: should not err out file delete $testfile # second call: with a single process this is no problem file delete $testfile } # End of file tclsh8.5 t.tcl => runs ok tclsh8.5 t.tcl & tclsh8.5 t.tcl => immediate error from one of the processes error deleting "/tmp/testfile": no such file or directory while executing "file delete $testfile" ("while" body line 3) invoked from within "while {1} { catch {close [open $testfile w]} file delete $testfile file delete $testfile }" (file "t.tcl" line 3) According to the documentation this error should never occur. Citing a message on comp.lang.tcl: From: Ralf Fassel <[email protected]> Newsgroups: comp.lang.tcl Subject: Re: catch and trap Date: Thu, 23 Oct 2008 22:08:48 +0200 Message-ID: <[email protected]> * "Donal K. Fellows" <[email protected]> | In order to know which syscall to use, Tcl has to lstat() it first | (lstat because we want to just remove the link if it is a symlink to | a directory); if we get ENOENT from the lstat(), we don't bother | doing anything else as the file is (probably) gone; --<snip-snip>-- But if the file is there at lstat-time, and it is a file, then in tcl-8.5.2 the result of result = Tcl_FSDeleteFile(objv[i]); is returned, which boils down to calling unlink(2) on Unix, which returns an ENOENT error for non-existing files, and *this* is then translated into TCL_ERROR (unix/tclUnixFCmd.c, TclpDeleteFile()). Proposed patch for Unix: *** tcl8.5.5/unix/tclUnixFCmd.c~Thu Dec 13 16:28:42 2007 --- tcl8.5.5/unix/tclUnixFCmd.cMon Dec 8 15:11:58 2008 *************** *** 633,639 **** TclpDeleteFile( CONST char *path)/* Pathname of file to be removed (native). */ { ! if (unlink(path) != 0) {/* INTL: Native. */ return TCL_ERROR; } return TCL_OK; --- 633,639 ---- TclpDeleteFile( CONST char *path)/* Pathname of file to be removed (native). */ { ! if (unlink(path) != 0 && errno != ENOENT) {/* INTL: Native. */ return TCL_ERROR; } return TCL_OK; Diff finished. Mon Dec 8 15:12:04 2008 patches for windows & mac ? - foundin changed to: "obsolete: 8.5.5"
- is_private changed to: "0"
- priority changed to: "5 Medium"
- resolution changed to: "None"
- status changed to: "Open"
- submitter changed to: "ralfixx"
- subsystem changed to: "37. File System"
- title changed to: "file delete reports an error on non-existent file"
- type changed to: "Bug"