Skip to content

Commit 2f22f43

Browse files
committed
os: Truncate on Windows will not create a new file
Truncating a non existent file currently creates a new blank file. This behavior is not consistent with other OSes where a file not found error would instead be returned. This change makes Truncate on Windows return a file-not-found error when the specified file doesn't exist, bringing the behavior consistent. Fixes 58977
1 parent 3360be4 commit 2f22f43

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/os/file_windows.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ func (f *File) seek(offset int64, whence int) (ret int64, err error) {
160160
// Truncate changes the size of the named file.
161161
// If the file is a symbolic link, it changes the size of the link's target.
162162
func Truncate(name string, size int64) error {
163-
f, e := OpenFile(name, O_WRONLY|O_CREATE, 0666)
163+
f, e := OpenFile(name, O_WRONLY, 0666)
164164
if e != nil {
165165
return e
166166
}

0 commit comments

Comments
 (0)