Ticket UUID: | 1622579 | |||
Title: | open fails to open hidden files for writing | |||
Type: | Bug | Version: | obsolete: 8.4.14 | |
Submitter: | fvogel | Created on: | 2006-12-26 20:53:00 | |
Subsystem: | 25. Channel System | Assigned To: | andreas_kupries | |
Priority: | 5 Medium | Severity: | ||
Status: | Closed | Last Modified: | 2014-02-19 20:32:33 | |
Resolution: | Wont Fix | Closed By: | dkf | |
Closed on: | 2007-01-03 22:51:46 | |||
Description: |
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 | |||
User Comments: |
fvogelnew1 added on 2007-01-04 03:38:29:
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 patthoyts added on 2007-01-03 20:40:45: 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. |