IOUtils.createUniqueFile doesn't work on Windows if filename contains colon
Categories
(Toolkit Graveyard :: OS.File, defect)
Tracking
(Not tracked)
People
(Reporter: rnons, Unassigned)
References
Details
I don't know if this is a bug or expected behavior, when the filename contains a colon, createFileUnique
doesn't work on Windows.
await IOUtils.createUniqueFile("C:\\mozilla-central", "a:b")
// "C:\\mozilla-central\\a:b"
await IOUtils.createUniqueFile("C:\\mozilla-central", "a:b")
// "C:\\mozilla-central\\a:b-1"
createUniqueFile
was called twice, but only one file named a
was created.
Comment 1•2 years ago
|
||
Windows does not support files with a colon in them. The colon is used as a drive separator:
Barret@THEOBROMA ~ $ mkdir foo
Directory: C:\Users\Barret
Mode LastWriteTime Length Name
---- ------------- ------ ----
d---- 2022-10-05 12:36 PM foo
Barret@THEOBROMA ~ $ cd foo
Barret@THEOBROMA ~\foo $ echo "asdf" > ".\a:b"
Barret@THEOBROMA ~\foo $ dir
Directory: C:\Users\Barret\foo
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 2022-10-05 12:36 PM 0 a
```
This behaviour is as expected.
Comment 2•2 years ago
|
||
The reported behaviour requires sanitizing every input to createUniqueFile() in each usage, where filenames are constructed from strings not directly returned by the underlaying filesystem. It therefore seems plausible to sanitize the input filename automatically, to reduce redundancy and to prevent unexpected errors.
There is already a hardcoded set of invalid characters:
https://searchfox.org/mozilla-central/rev/80e1bfa13c954e6450a13b3cc802d82773eba2e0/xpcom/base/nsCRTGlue.h#139
Comment 3•2 years ago
|
||
As we're talking about createUniqueFile here, I think it would seem fine to just automatically replace the problematic characters with _. Callers of createUniqueFile do not care that much about the actual file name being used in the end.
Updated•1 year ago
|
Description
•