You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Second, a bug report:
In the occasion of "overwriting file" with GCS FS using afero.WriteFile (or fs.OpenFile), the way in which flags are processed seems to be incorrect.
afero.WriteFile calls fs.OpenFile with flags being os.O_WRONLY|os.O_CREATE|os.O_TRUNC which works like a charm for creating new files or truncating existing ones with local FS. However, with GCS FS, when the file does not exist, such call fails with storage: object doesn't exist.
Example code:
package main
import (
"context""fmt""github.com/spf13/afero""github.com/spf13/afero/gcsfs""os"
)
funcmain() {
filename:="mybucket/myfile.txt"// bucket exists, but not the filefs, err:=gcsfs.NewGcsFS(context.Background())
iferr!=nil {
panic(err)
}
iferr:=afero.WriteFile(fs, filename, []byte("Hello"), os.ModePerm); err!=nil {
fmt.Printf("%s\n", err) // will print "storage: object doesn't exist"
}
}
Looking at the gcsfs/fs.go it's clear that os.O_TRUNC tries to delete non-existent file without checking for os.O_CREATE flag to be present.
I'm capable of providing a PR with the solution to the issue, but just wanted to make sure this is not something already being addressed or was considered an expected behaviour.
The text was updated successfully, but these errors were encountered:
First, thanks for the great product!
Second, a bug report:
In the occasion of "overwriting file" with GCS FS using
afero.WriteFile
(orfs.OpenFile
), the way in which flags are processed seems to be incorrect.afero.WriteFile
callsfs.OpenFile
with flags beingos.O_WRONLY|os.O_CREATE|os.O_TRUNC
which works like a charm for creating new files or truncating existing ones with local FS. However, with GCS FS, when the file does not exist, such call fails withstorage: object doesn't exist
.Example code:
Looking at the gcsfs/fs.go it's clear that
os.O_TRUNC
tries to delete non-existent file without checking foros.O_CREATE
flag to be present.I'm capable of providing a PR with the solution to the issue, but just wanted to make sure this is not something already being addressed or was considered an expected behaviour.
The text was updated successfully, but these errors were encountered: