Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#3608 open fails to open hidden files for writing

obsolete: 8.4.14
closed-wont-fix
5
2007-01-03
2006-12-26
Francois VOGEL
No

On Windows XP, create any file and give it the readonly attribute through the properties dialog.

Then, try to open this file for writing:

open "bizarre1_hidden.log2": w

Tcl complains:

couldn't open "bizarre1_hidden.log2": permission denied

I can see no reason for that.
Especially, the file is writable:

% file writable bizarre1_hidden.log2
1

Francois

Discussion

  • Pat Thoyts
    Pat Thoyts
    2007-01-03

    Logged In: YES
    user_id=202636
    Originator: NO

    "give it the readonly attribute"
    You mean hidden.

    The issue here is that the file exists already with non-default attributes. Mode 'w' means WRONLY|CREAT|TRUNC which is translated into OPEN_ALWAYS and as we look like we are creating the file we expect to set the attributes to FILE_ATTRIBUTE_NORMAL. As the file exists but has FILE_ATTRIBUTE_HIDDEN we get a permission denied from windows.

    The solution is to open with appropriate flags:
    % set f [open z.txt w]; puts $f test; close $f
    % file attributes z.txt -hidden 1
    %
    % list [set f [open z.txt w]] [close $f]
    couldn't open "z.txt": permission denied
    % list [set f [open z.txt a]] [close $f]
    filea260e8 {}
    % list [set f [open z.txt a+]] [close $f]
    filea21648 {}
    % list [set f [open z.txt "WRONLY CREAT"]] [close $f]
    filea26150
    % list [set f [open z.txt "WRONLY CREAT TRUNC"]] [close $f]
    couldn't open "z.txt": permission denied

    I don't think this is a bug myself.

     
  • Pat Thoyts
    Pat Thoyts
    2007-01-03

    • status: open --> pending-wont-fix
     
  • Francois VOGEL
    Francois VOGEL
    2007-01-03

    • status: pending-wont-fix --> open-wont-fix
     
  • Francois VOGEL
    Francois VOGEL
    2007-01-03

    Logged In: YES
    user_id=1245417
    Originator: YES

    I understand your answer and I thank you very much for your so clear explanations.

    What I need is a mode that will let me write my file in any case, i.e. to overwrite if the file exists (no append), or to create the file if it does not yet exist. And this, whether the file is hidden or not.

    From the "open" man page, I had understood that "WRONLY CREAT TRUNC" was what I needed, and translated this simply into "w".

    I now understand that I should use "WRONLY CREAT", right?

    But for TRUNC I can read:
    "If the file exists it is truncated to zero length."

    But this seems to be what I need! Because otherwise I would append, or am I missing something?

    Anyway, it seems from my tests that I actually don't need the TRUNC parameter. Question is "why?"

    Thanks,
    Francois

     
    • status: open-wont-fix --> closed-wont-fix