Tcl Source Code

View Ticket
Login
Ticket UUID: 2935503
Title: Incorrect mode field returned by file stat command
Type: Bug Created on: 2010-01-20 09:25:12
Submitter: apnadkarni Assigned to: nijtmans
Subsystem: 37. File System Severity:
Priority: 5 Medium Last modified: 2012-06-22 20:01:56
Status: Closed Closed by: nijtmans
Resolution: Fixed Closed on: 2012-06-22 13:01:56
Version: obsolete: 8.4.19
Description:
From c.l.t  posting by keithv -
----
Is the mode value from file stat meaningful on Windows.
Under tcl 8.5, it always seems to return 0644
even if you have permission write to the file.

(This problem came up when I was trying to figure
out why tcllib's ftpd package wouldn't let me delete
a file.)

Thanks,
Keith 
----

Looking at the code, the problem is in the NativeStatMode function in tclWinFile.c
The lines propagating the owner bits to group and others -
    mode |= (mode & 0x0700) >> 3;
    mode |= (mode & 0x0700) >> 6;
should be
    mode |= (mode & 0700) >> 3;
    mode |= (mode & 0700) >> 6;

(i.e. octal 700, not hex)

/Ashok
User Comments:
apnadkarni added on 2011-08-25 22:21:49:
Reassigned to dgp as per instruction from him

nijtmans added on 2011-10-11 20:39:22:
This one is so trivial, just let's fix it.....

Test io-40.2, which was previously unix-only
adapted to show how valid this bug report is.

Fixed in all open branches.

dgp added on 2011-10-13 00:24:34:
Test fails in a tcl/unix build on OSX Snow Leopard:


==== io-40.2 POSIX open access modes: CREAT FAILED
==== Contents of test case:

    file delete $path(test3)
    set f [open $path(test3) {WRONLY CREAT} 0o666]
    file stat $path(test3) stats
    set x [format "0o%o" [expr $stats(mode)&0o777]]
    puts $f "line 1"
    close $f
    set f [open $path(test3) r]
    lappend x [gets $f]
    close $f
    set x

---- Result was:
0o644 {line 1}
---- Result should have been (exact matching):
0o666 {line 1}
==== io-40.2 FAILED

dgp added on 2011-10-13 01:43:15:
Same failure on Centos system.

dgp added on 2011-10-13 01:46:55:
Just because we ask for permissions 0o666
doesn't mean we'll get them depending on
what permissions we have on the containing dir.

andreas_kupries added on 2011-10-13 01:53:39:
And the user's 'umask' settings in the current shell may effect results too.

nijtmans added on 2011-10-13 15:04:21:
Reverting test-case, als the actual change is Windows-only anyway.

So it was not that trivial.......

nijtmans added on 2012-06-22 20:01:56:

allow_comments - 1