Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2016-07-09
14:32 • Closed ticket [ae61a67192]: file type on Windows generates error for built-in fi... artifact: 720f53962f user: apnadkarni
14:32 • Ticket [ae61a67192]: 3 changes artifact: ebbd6f0aff user: apnadkarni
14:25 • Ticket [ae61a67192]: 3 changes artifact: de5ef37b5a user: dgp
08:30 • Ticket [ae61a67192]: 3 changes artifact: e6265268a9 user: apnadkarni
08:27
Bugfix [ae61a67192]. file {stat, type, size} etc. support for built-in special Windows files/devices... check-in: 5e0bded748 user: ashok tags: core-8-6-branch
2016-07-08
16:40 • Ticket [ae61a67192] file type on Windows generates error for built-in file names... artifact: 7af8be00a4 user: apnadkarni
16:06 • Ticket [ae61a67192]: 3 changes artifact: 9ab66b198e user: sebres
15:39 • Ticket [ae61a67192]: 3 changes artifact: ceeffa1ee0 user: apnadkarni
13:25 • Ticket [ae61a67192]: 4 changes artifact: 370a902b0d user: sebres
12:31 • Ticket [ae61a67192]: 3 changes artifact: 48c560404e user: apnadkarni
08:27 • New ticket [ae61a67192]. artifact: f5f9520dd4 user: apnadkarni

file type on Windows generates error for built-in file names like CON

Closed / Fixedae61a67192e4a9ffea855790efc373ddb440926aCreated 10 years agoUpdated 10 years ago
Descriptionplain2016-07-08 08:27:44
% file exists con
1
% file type con
could not read "con": bad file number

Names like CON, LPT etc. are built-in hardcoded names in Windows.
Referenced by1
  • 5e0bded748Bugfix [ae61a67192]. file {stat, type, size} etc. support for built-in special Windows files/devices like CON. check-in2016-07-09 08:27:00
apnadkarniplain2016-07-08 12:31:46
Actually anything depending stat does not work (file size etc.) for the built in names. Note that channel commands like open and puts work fine.
sebreshtml2016-07-08 13:25:03

FWIW: pair articles about forbidden file and folder names on windows:


IMHO important also: In addition, any combinations of these with extensions are not allowed.

See example:
% file exists con.txt
1
% file type con.txt
could not read "con.txt": no such file or directory

apnadkarniplain2016-07-08 15:39:16
Working on a patch for this.

file type con
file type c:/temp/con
file type c:/temp/con.txt

should all return characterSpecial.

file size for all should return 0

file stat should return semi-sensible information.

Note you can open c:/temp/con.txt and write to it. Output goes to the console. This is Microsoft defined and implemented behavior. Yes, DOS 1.0 compatibility!
sebresplain2016-07-08 16:06:52
> Note you can open c:/temp/con.txt and write to it. Output goes to the console.

What I meant was, that described behavior for special built-in names are expected to be fixed as well as without extension and with extension also.

So in the possible fix only the name of file should be verified (without given extension or directory if it was specified)...

I mean something like (following code in tcl):
```
if {[string tolower [file root [file tail "c:/a/b/c/con.txt"]]] in {con lpt ...}} {
  ... special case (no file) ...
} else {
  ... file or directory ...
}
```
apnadkarniplain2016-07-08 16:40:40
I have a patch mostly working except that I’m undecided as to what to do about the stat atime/mtime/ctime fields since afaik these are not maintained by Windows for special devices like CON, PRN etc.. The current documentation for [file atime/mtime] says an error is raised if these values are not available. However, there is no way currently in the Tcl implementation to signal an error only for these commands without erroring on *any* stat related call targeting those devices. 

I could either

- Return 0 in the stat.st_atime/mtime field which is somewhat misleading unless we specifically change the document as such, or
- Return special value -1 (or even 0) *and* modify the [file atime/mtime] implementation to raise an error on this value, or
- Leave things as they are (ie. All stat related calls will error out on these files though open et al work)

I would prefer the second approach except that I’m afraid this change might impact currently working code that happily supplies and accepts this “special” value in these fields on other platforms.

Anyone have opinions/suggestions?
apnadkarniwiki2016-07-09 08:30:04

Checked in patch [5e0bded748]. file {stat, size, type} should now work with special built-in Windows files. file atime,mtime continue to raise an error as documented.

dgpplain2016-07-09 14:25:16
New tests cmdAH-28.13* fail on Mac OSX.

Tests need constraint?
apnadkarniplain2016-07-09 14:32:06
Yes indeed. I thought I had included them as needed. Apparently not. Fixed in [270139a1e3]
apnadkarni Closed ticket [ae61a67192]. [History diff]2016-07-09 14:32:45
Log in (anonymous is fine) to add a comment.