mirror of
https://github.com/rclone/rclone.git
synced 2025-12-11 22:14:05 +01:00
vfs: Make OpenFile and friends return EINVAL if O_RDONLY and O_TRUNC
Before this change Open("name", os.O_RDONLY|os.O_TRUNC) would have
truncated the file. This is what Linux does, but is counterintuitive.
POSIX states this is undefined, so return an error in this case
instead. This preserves the invariant O_RDONLY => file is not
changed.
This commit is contained in:
168
vfs/open_test.go
168
vfs/open_test.go
@@ -36,13 +36,13 @@ var openTests = []openTest{
|
||||
}, {
|
||||
flags: os.O_RDONLY | os.O_TRUNC,
|
||||
what: "os.O_RDONLY|os.O_TRUNC",
|
||||
openNonExistentErr: ENOENT,
|
||||
openNonExistentErr: EINVAL,
|
||||
readNonExistentErr: nil,
|
||||
writeNonExistentErr: nil,
|
||||
openExistingErr: nil,
|
||||
readExistingErr: io.EOF,
|
||||
writeExistingErr: EBADF,
|
||||
contents: "",
|
||||
openExistingErr: EINVAL,
|
||||
readExistingErr: nil,
|
||||
writeExistingErr: nil,
|
||||
contents: "hello",
|
||||
}, {
|
||||
flags: os.O_RDONLY | os.O_SYNC,
|
||||
what: "os.O_RDONLY|os.O_SYNC",
|
||||
@@ -56,13 +56,13 @@ var openTests = []openTest{
|
||||
}, {
|
||||
flags: os.O_RDONLY | os.O_SYNC | os.O_TRUNC,
|
||||
what: "os.O_RDONLY|os.O_SYNC|os.O_TRUNC",
|
||||
openNonExistentErr: ENOENT,
|
||||
openNonExistentErr: EINVAL,
|
||||
readNonExistentErr: nil,
|
||||
writeNonExistentErr: nil,
|
||||
openExistingErr: nil,
|
||||
readExistingErr: io.EOF,
|
||||
writeExistingErr: EBADF,
|
||||
contents: "",
|
||||
openExistingErr: EINVAL,
|
||||
readExistingErr: nil,
|
||||
writeExistingErr: nil,
|
||||
contents: "hello",
|
||||
}, {
|
||||
flags: os.O_RDONLY | os.O_EXCL,
|
||||
what: "os.O_RDONLY|os.O_EXCL",
|
||||
@@ -76,13 +76,13 @@ var openTests = []openTest{
|
||||
}, {
|
||||
flags: os.O_RDONLY | os.O_EXCL | os.O_TRUNC,
|
||||
what: "os.O_RDONLY|os.O_EXCL|os.O_TRUNC",
|
||||
openNonExistentErr: ENOENT,
|
||||
openNonExistentErr: EINVAL,
|
||||
readNonExistentErr: nil,
|
||||
writeNonExistentErr: nil,
|
||||
openExistingErr: nil,
|
||||
readExistingErr: io.EOF,
|
||||
writeExistingErr: EBADF,
|
||||
contents: "",
|
||||
openExistingErr: EINVAL,
|
||||
readExistingErr: nil,
|
||||
writeExistingErr: nil,
|
||||
contents: "hello",
|
||||
}, {
|
||||
flags: os.O_RDONLY | os.O_EXCL | os.O_SYNC,
|
||||
what: "os.O_RDONLY|os.O_EXCL|os.O_SYNC",
|
||||
@@ -96,13 +96,13 @@ var openTests = []openTest{
|
||||
}, {
|
||||
flags: os.O_RDONLY | os.O_EXCL | os.O_SYNC | os.O_TRUNC,
|
||||
what: "os.O_RDONLY|os.O_EXCL|os.O_SYNC|os.O_TRUNC",
|
||||
openNonExistentErr: ENOENT,
|
||||
openNonExistentErr: EINVAL,
|
||||
readNonExistentErr: nil,
|
||||
writeNonExistentErr: nil,
|
||||
openExistingErr: nil,
|
||||
readExistingErr: io.EOF,
|
||||
writeExistingErr: EBADF,
|
||||
contents: "",
|
||||
openExistingErr: EINVAL,
|
||||
readExistingErr: nil,
|
||||
writeExistingErr: nil,
|
||||
contents: "hello",
|
||||
}, {
|
||||
flags: os.O_RDONLY | os.O_CREATE,
|
||||
what: "os.O_RDONLY|os.O_CREATE",
|
||||
@@ -116,13 +116,13 @@ var openTests = []openTest{
|
||||
}, {
|
||||
flags: os.O_RDONLY | os.O_CREATE | os.O_TRUNC,
|
||||
what: "os.O_RDONLY|os.O_CREATE|os.O_TRUNC",
|
||||
openNonExistentErr: nil,
|
||||
readNonExistentErr: io.EOF,
|
||||
writeNonExistentErr: EBADF,
|
||||
openExistingErr: nil,
|
||||
readExistingErr: io.EOF,
|
||||
writeExistingErr: EBADF,
|
||||
contents: "",
|
||||
openNonExistentErr: EINVAL,
|
||||
readNonExistentErr: nil,
|
||||
writeNonExistentErr: nil,
|
||||
openExistingErr: EINVAL,
|
||||
readExistingErr: nil,
|
||||
writeExistingErr: nil,
|
||||
contents: "hello",
|
||||
}, {
|
||||
flags: os.O_RDONLY | os.O_CREATE | os.O_SYNC,
|
||||
what: "os.O_RDONLY|os.O_CREATE|os.O_SYNC",
|
||||
@@ -136,13 +136,13 @@ var openTests = []openTest{
|
||||
}, {
|
||||
flags: os.O_RDONLY | os.O_CREATE | os.O_SYNC | os.O_TRUNC,
|
||||
what: "os.O_RDONLY|os.O_CREATE|os.O_SYNC|os.O_TRUNC",
|
||||
openNonExistentErr: nil,
|
||||
readNonExistentErr: io.EOF,
|
||||
writeNonExistentErr: EBADF,
|
||||
openExistingErr: nil,
|
||||
readExistingErr: io.EOF,
|
||||
writeExistingErr: EBADF,
|
||||
contents: "",
|
||||
openNonExistentErr: EINVAL,
|
||||
readNonExistentErr: nil,
|
||||
writeNonExistentErr: nil,
|
||||
openExistingErr: EINVAL,
|
||||
readExistingErr: nil,
|
||||
writeExistingErr: nil,
|
||||
contents: "hello",
|
||||
}, {
|
||||
flags: os.O_RDONLY | os.O_CREATE | os.O_EXCL,
|
||||
what: "os.O_RDONLY|os.O_CREATE|os.O_EXCL",
|
||||
@@ -156,10 +156,10 @@ var openTests = []openTest{
|
||||
}, {
|
||||
flags: os.O_RDONLY | os.O_CREATE | os.O_EXCL | os.O_TRUNC,
|
||||
what: "os.O_RDONLY|os.O_CREATE|os.O_EXCL|os.O_TRUNC",
|
||||
openNonExistentErr: nil,
|
||||
readNonExistentErr: io.EOF,
|
||||
writeNonExistentErr: EBADF,
|
||||
openExistingErr: EEXIST,
|
||||
openNonExistentErr: EINVAL,
|
||||
readNonExistentErr: nil,
|
||||
writeNonExistentErr: nil,
|
||||
openExistingErr: EINVAL,
|
||||
readExistingErr: nil,
|
||||
writeExistingErr: nil,
|
||||
contents: "hello",
|
||||
@@ -176,10 +176,10 @@ var openTests = []openTest{
|
||||
}, {
|
||||
flags: os.O_RDONLY | os.O_CREATE | os.O_EXCL | os.O_SYNC | os.O_TRUNC,
|
||||
what: "os.O_RDONLY|os.O_CREATE|os.O_EXCL|os.O_SYNC|os.O_TRUNC",
|
||||
openNonExistentErr: nil,
|
||||
readNonExistentErr: io.EOF,
|
||||
writeNonExistentErr: EBADF,
|
||||
openExistingErr: EEXIST,
|
||||
openNonExistentErr: EINVAL,
|
||||
readNonExistentErr: nil,
|
||||
writeNonExistentErr: nil,
|
||||
openExistingErr: EINVAL,
|
||||
readExistingErr: nil,
|
||||
writeExistingErr: nil,
|
||||
contents: "hello",
|
||||
@@ -196,13 +196,13 @@ var openTests = []openTest{
|
||||
}, {
|
||||
flags: os.O_RDONLY | os.O_APPEND | os.O_TRUNC,
|
||||
what: "os.O_RDONLY|os.O_APPEND|os.O_TRUNC",
|
||||
openNonExistentErr: ENOENT,
|
||||
openNonExistentErr: EINVAL,
|
||||
readNonExistentErr: nil,
|
||||
writeNonExistentErr: nil,
|
||||
openExistingErr: nil,
|
||||
readExistingErr: io.EOF,
|
||||
writeExistingErr: EBADF,
|
||||
contents: "",
|
||||
openExistingErr: EINVAL,
|
||||
readExistingErr: nil,
|
||||
writeExistingErr: nil,
|
||||
contents: "hello",
|
||||
}, {
|
||||
flags: os.O_RDONLY | os.O_APPEND | os.O_SYNC,
|
||||
what: "os.O_RDONLY|os.O_APPEND|os.O_SYNC",
|
||||
@@ -216,13 +216,13 @@ var openTests = []openTest{
|
||||
}, {
|
||||
flags: os.O_RDONLY | os.O_APPEND | os.O_SYNC | os.O_TRUNC,
|
||||
what: "os.O_RDONLY|os.O_APPEND|os.O_SYNC|os.O_TRUNC",
|
||||
openNonExistentErr: ENOENT,
|
||||
openNonExistentErr: EINVAL,
|
||||
readNonExistentErr: nil,
|
||||
writeNonExistentErr: nil,
|
||||
openExistingErr: nil,
|
||||
readExistingErr: io.EOF,
|
||||
writeExistingErr: EBADF,
|
||||
contents: "",
|
||||
openExistingErr: EINVAL,
|
||||
readExistingErr: nil,
|
||||
writeExistingErr: nil,
|
||||
contents: "hello",
|
||||
}, {
|
||||
flags: os.O_RDONLY | os.O_APPEND | os.O_EXCL,
|
||||
what: "os.O_RDONLY|os.O_APPEND|os.O_EXCL",
|
||||
@@ -236,13 +236,13 @@ var openTests = []openTest{
|
||||
}, {
|
||||
flags: os.O_RDONLY | os.O_APPEND | os.O_EXCL | os.O_TRUNC,
|
||||
what: "os.O_RDONLY|os.O_APPEND|os.O_EXCL|os.O_TRUNC",
|
||||
openNonExistentErr: ENOENT,
|
||||
openNonExistentErr: EINVAL,
|
||||
readNonExistentErr: nil,
|
||||
writeNonExistentErr: nil,
|
||||
openExistingErr: nil,
|
||||
readExistingErr: io.EOF,
|
||||
writeExistingErr: EBADF,
|
||||
contents: "",
|
||||
openExistingErr: EINVAL,
|
||||
readExistingErr: nil,
|
||||
writeExistingErr: nil,
|
||||
contents: "hello",
|
||||
}, {
|
||||
flags: os.O_RDONLY | os.O_APPEND | os.O_EXCL | os.O_SYNC,
|
||||
what: "os.O_RDONLY|os.O_APPEND|os.O_EXCL|os.O_SYNC",
|
||||
@@ -256,13 +256,13 @@ var openTests = []openTest{
|
||||
}, {
|
||||
flags: os.O_RDONLY | os.O_APPEND | os.O_EXCL | os.O_SYNC | os.O_TRUNC,
|
||||
what: "os.O_RDONLY|os.O_APPEND|os.O_EXCL|os.O_SYNC|os.O_TRUNC",
|
||||
openNonExistentErr: ENOENT,
|
||||
openNonExistentErr: EINVAL,
|
||||
readNonExistentErr: nil,
|
||||
writeNonExistentErr: nil,
|
||||
openExistingErr: nil,
|
||||
readExistingErr: io.EOF,
|
||||
writeExistingErr: EBADF,
|
||||
contents: "",
|
||||
openExistingErr: EINVAL,
|
||||
readExistingErr: nil,
|
||||
writeExistingErr: nil,
|
||||
contents: "hello",
|
||||
}, {
|
||||
flags: os.O_RDONLY | os.O_APPEND | os.O_CREATE,
|
||||
what: "os.O_RDONLY|os.O_APPEND|os.O_CREATE",
|
||||
@@ -276,13 +276,13 @@ var openTests = []openTest{
|
||||
}, {
|
||||
flags: os.O_RDONLY | os.O_APPEND | os.O_CREATE | os.O_TRUNC,
|
||||
what: "os.O_RDONLY|os.O_APPEND|os.O_CREATE|os.O_TRUNC",
|
||||
openNonExistentErr: nil,
|
||||
readNonExistentErr: io.EOF,
|
||||
writeNonExistentErr: EBADF,
|
||||
openExistingErr: nil,
|
||||
readExistingErr: io.EOF,
|
||||
writeExistingErr: EBADF,
|
||||
contents: "",
|
||||
openNonExistentErr: EINVAL,
|
||||
readNonExistentErr: nil,
|
||||
writeNonExistentErr: nil,
|
||||
openExistingErr: EINVAL,
|
||||
readExistingErr: nil,
|
||||
writeExistingErr: nil,
|
||||
contents: "hello",
|
||||
}, {
|
||||
flags: os.O_RDONLY | os.O_APPEND | os.O_CREATE | os.O_SYNC,
|
||||
what: "os.O_RDONLY|os.O_APPEND|os.O_CREATE|os.O_SYNC",
|
||||
@@ -296,13 +296,13 @@ var openTests = []openTest{
|
||||
}, {
|
||||
flags: os.O_RDONLY | os.O_APPEND | os.O_CREATE | os.O_SYNC | os.O_TRUNC,
|
||||
what: "os.O_RDONLY|os.O_APPEND|os.O_CREATE|os.O_SYNC|os.O_TRUNC",
|
||||
openNonExistentErr: nil,
|
||||
readNonExistentErr: io.EOF,
|
||||
writeNonExistentErr: EBADF,
|
||||
openExistingErr: nil,
|
||||
readExistingErr: io.EOF,
|
||||
writeExistingErr: EBADF,
|
||||
contents: "",
|
||||
openNonExistentErr: EINVAL,
|
||||
readNonExistentErr: nil,
|
||||
writeNonExistentErr: nil,
|
||||
openExistingErr: EINVAL,
|
||||
readExistingErr: nil,
|
||||
writeExistingErr: nil,
|
||||
contents: "hello",
|
||||
}, {
|
||||
flags: os.O_RDONLY | os.O_APPEND | os.O_CREATE | os.O_EXCL,
|
||||
what: "os.O_RDONLY|os.O_APPEND|os.O_CREATE|os.O_EXCL",
|
||||
@@ -316,10 +316,10 @@ var openTests = []openTest{
|
||||
}, {
|
||||
flags: os.O_RDONLY | os.O_APPEND | os.O_CREATE | os.O_EXCL | os.O_TRUNC,
|
||||
what: "os.O_RDONLY|os.O_APPEND|os.O_CREATE|os.O_EXCL|os.O_TRUNC",
|
||||
openNonExistentErr: nil,
|
||||
readNonExistentErr: io.EOF,
|
||||
writeNonExistentErr: EBADF,
|
||||
openExistingErr: EEXIST,
|
||||
openNonExistentErr: EINVAL,
|
||||
readNonExistentErr: nil,
|
||||
writeNonExistentErr: nil,
|
||||
openExistingErr: EINVAL,
|
||||
readExistingErr: nil,
|
||||
writeExistingErr: nil,
|
||||
contents: "hello",
|
||||
@@ -336,10 +336,10 @@ var openTests = []openTest{
|
||||
}, {
|
||||
flags: os.O_RDONLY | os.O_APPEND | os.O_CREATE | os.O_EXCL | os.O_SYNC | os.O_TRUNC,
|
||||
what: "os.O_RDONLY|os.O_APPEND|os.O_CREATE|os.O_EXCL|os.O_SYNC|os.O_TRUNC",
|
||||
openNonExistentErr: nil,
|
||||
readNonExistentErr: io.EOF,
|
||||
writeNonExistentErr: EBADF,
|
||||
openExistingErr: EEXIST,
|
||||
openNonExistentErr: EINVAL,
|
||||
readNonExistentErr: nil,
|
||||
writeNonExistentErr: nil,
|
||||
openExistingErr: EINVAL,
|
||||
readExistingErr: nil,
|
||||
writeExistingErr: nil,
|
||||
contents: "hello",
|
||||
|
||||
Reference in New Issue
Block a user