diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2021-12-05 18:08:55 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2021-12-05 18:47:02 +0900 |
commit | b555e659c4974acc423083b71b1bd5ec6a926046 (patch) | |
tree | 93ff0dca0caad6d738fee12c5c61a884cdc87618 /io.c | |
parent | a72aecac3ae81e955997e4d789504e60196e2697 (diff) |
Do not use `fcopyfile` if appending to non-empty file [Bug #18388]
`fcopyfile` appends `src` to `to` and then truncates `to` to it's
original size.
Diffstat (limited to 'io.c')
-rw-r--r-- | io.c | 7 |
1 files changed, 7 insertions, 0 deletions
@@ -11483,6 +11483,13 @@ nogvl_fcopyfile(struct copy_stream_struct *stp) return 0; if (lseek(stp->dst_fptr->fd, 0, SEEK_CUR) > (off_t)0) /* if dst IO was already written */ return 0; + if (fcntl(stp->dst_fptr->fd, F_GETFL) & O_APPEND) { + /* fcopyfile(3) appends src IO to dst IO and then truncates + * dst IO to src IO's original size. */ + off_t end = lseek(stp->dst_fptr->fd, 0, SEEK_END); + lseek(stp->dst_fptr->fd, 0, SEEK_SET); + if (end > (off_t)0) return 0; + } if (src_offset > (off_t)0) { off_t r; |