From: Cyrill Gorcunov <gorcunov@gmail.com> To: tml <tarantool-patches@freelists.org> Cc: Vladimir Davydov <vdavydov.dev@gmail.com>, Cyrill Gorcunov <gorcunov@gmail.com> Subject: [PATCH] core/coio_file: copyfile -- Make it behave as regular cp Date: Sat, 4 May 2019 18:49:22 +0300 [thread overview] Message-ID: <20190504154922.30072-1-gorcunov@gmail.com> (raw) Traditional cp utility opens destination with O_TRUNC flag, iow it drops old content of the target file if such exists. Fixes #4181 --- https://github.com/tarantool/tarantool/issues/4181 Guys, take a look please, this is change in behaviour but should be acceptable. Also I just wondered that most of tests in test/app/fio.test.lua do pass octal modes as 0777 while lua's number parser simply doesn't understand octal form. So that I had to pass mode 420 by hands which is an alias to 0644. src/lib/core/coio_file.c | 2 +- test/app/fio.result | 23 +++++++++++++++++++++++ test/app/fio.test.lua | 9 ++++++++- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/lib/core/coio_file.c b/src/lib/core/coio_file.c index 3caf185a5..3359f42bc 100644 --- a/src/lib/core/coio_file.c +++ b/src/lib/core/coio_file.c @@ -584,7 +584,7 @@ coio_do_copyfile(eio_req *req) goto error; } - int dest_fd = open(eio->copyfile.dest, O_WRONLY | O_CREAT, + int dest_fd = open(eio->copyfile.dest, O_WRONLY|O_CREAT|O_TRUNC, st.st_mode & 0777); if (dest_fd < 0) { goto error_dest; diff --git a/test/app/fio.result b/test/app/fio.result index 879e0a767..32f8d6868 100644 --- a/test/app/fio.result +++ b/test/app/fio.result @@ -721,6 +721,9 @@ file3 = fio.pathjoin(tree, 'file.3') file4 = fio.pathjoin(tree, 'file.4') --- ... +file5 = fio.pathjoin(tree, 'file.5') +--- +... fh1 = fio.open(file1, { 'O_RDWR', 'O_TRUNC', 'O_CREAT' }, 0777) --- ... @@ -775,6 +778,26 @@ errinj.set('ERRINJ_COIO_SENDFILE_CHUNK', -1) --- - ok ... +--- test the destination file is truncated +fh5 = fio.open(file5, { 'O_RDWR', 'O_TRUNC', 'O_CREAT' }, 420) +--- +... +fh5:write("to be truncated") +--- +- true +... +fh5:close() +--- +- true +... +fio.copyfile(file4, file5) +--- +- true +... +fio.stat(file4, file5) ~= nil +--- +- true +... res, err = fio.copyfile(fio.pathjoin(tmp1, 'not_exists.txt'), tmp1) --- ... diff --git a/test/app/fio.test.lua b/test/app/fio.test.lua index 1255b2804..b0d6c5f49 100644 --- a/test/app/fio.test.lua +++ b/test/app/fio.test.lua @@ -38,7 +38,6 @@ file2 = fio.pathjoin(tmpdir, 'file.2') file3 = fio.pathjoin(tmpdir, 'file.3') file4 = fio.pathjoin(tmpdir, 'file.4') - st, err = pcall(fio.open, nil) st err:match("open") ~= nil @@ -231,6 +230,7 @@ file1 = fio.pathjoin(tmp1, 'file.1') file2 = fio.pathjoin(tmp2, 'file.2') file3 = fio.pathjoin(tree, 'file.3') file4 = fio.pathjoin(tree, 'file.4') +file5 = fio.pathjoin(tree, 'file.5') fh1 = fio.open(file1, { 'O_RDWR', 'O_TRUNC', 'O_CREAT' }, 0777) fh1:write("gogo") @@ -249,6 +249,13 @@ fio.copyfile(file1, file4) fio.stat(file1, file4) ~= nil errinj.set('ERRINJ_COIO_SENDFILE_CHUNK', -1) +--- test the destination file is truncated +fh5 = fio.open(file5, { 'O_RDWR', 'O_TRUNC', 'O_CREAT' }, 420) +fh5:write("to be truncated") +fh5:close() +fio.copyfile(file4, file5) +fio.stat(file4, file5) ~= nil + res, err = fio.copyfile(fio.pathjoin(tmp1, 'not_exists.txt'), tmp1) res err:match("failed to copy") ~= nil -- 2.20.1
next reply other threads:[~2019-05-04 15:49 UTC|newest] Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-05-04 15:49 Cyrill Gorcunov [this message] 2019-05-06 8:37 ` Vladimir Davydov 2019-05-06 8:43 ` Cyrill Gorcunov 2019-05-06 9:59 ` [PATCH v2] " Cyrill Gorcunov 2019-05-06 10:09 ` Vladimir Davydov
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20190504154922.30072-1-gorcunov@gmail.com \ --to=gorcunov@gmail.com \ --cc=tarantool-patches@freelists.org \ --cc=vdavydov.dev@gmail.com \ --subject='Re: [PATCH] core/coio_file: copyfile -- Make it behave as regular cp' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox