Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2014-02-19
20:32 • Ticket [1622579fff] open fails to open hidden files for writing status still... artifact: e5e49d70cc user: andreask
2007-01-04
05:51 • Closed ticket [1622579fff]. artifact: d7678bb845 user: dkf
03:38 • Open ticket [1622579fff]. artifact: e16ca1b875 user: fvogelnew1
2007-01-03
20:40 • Pending ticket [1622579fff]. artifact: e9547fed5d user: patthoyts
2006-12-26
20:53 • New ticket [1622579fff]. artifact: 4483e22737 user: fvogelnew1

open fails to open hidden files for writing

Closed / Wont Fix1622579fffffffffffffffffffffffffffffffffCreated 20 years agoUpdated 13 years ago
Descriptionplain2006-12-26 20:53:00
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
patthoytsplain2007-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.
fvogelnew1plain2007-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
dkf Closed ticket [1622579fff]. [History diff]2007-01-04 05:51:46
andreask Ticket [1622579fff]: 1 change [History diff]2014-02-19 20:32:33
Log in (anonymous is fine) to add a comment.