From: Alexandre Oliva <oliva@adacore.com>
To: gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org
Subject: [PATCH] libstdc++: testsuite: fs rename to self may fail
Date: Wed, 22 Jun 2022 03:24:43 -0300 [thread overview]
Message-ID: <orilot9pw4.fsf@lxoliva.fsfla.org> (raw)
rtems6's rename() implementation errors with EEXIST when the rename-to
filename exists, even when renaming a file to itself or when renaming
a nonexisting file. Adjust expectations.
Regstrapped on x86_64-linux-gnu, also tested with a cross to
aarch64-rtems6. Ok to install?
PS: https://devel.rtems.org/ticket/2169 doesn't seem to suggest plans to
change behavior so as to comply with POSIX.
for libstdc++-v3/ChangeLog
* testsuite/27_io/filesystem/operations/rename.cc (test01):
Accept EEXIST fail on self-rename, on rename of a
nonexisting file, and on rename to existing file. Clean up p1
in case it remains.
* testsuite/experimental/filesystem/operations/rename.cc
(test01): Accept EEXIST fail on self-rename, and on rename to
existing file. Clean up p1 in case it remains.
---
.../27_io/filesystem/operations/rename.cc | 11 ++++++-----
.../experimental/filesystem/operations/rename.cc | 9 +++++----
2 files changed, 11 insertions(+), 9 deletions(-)
diff --git a/libstdc++-v3/testsuite/27_io/filesystem/operations/rename.cc b/libstdc++-v3/testsuite/27_io/filesystem/operations/rename.cc
index 936e306041290..2fb2068dfd3c5 100644
--- a/libstdc++-v3/testsuite/27_io/filesystem/operations/rename.cc
+++ b/libstdc++-v3/testsuite/27_io/filesystem/operations/rename.cc
@@ -46,14 +46,14 @@ test01()
ec = bad_ec;
std::ofstream{p1}; // create file
- fs::rename(p1, p1, ec); // no-op
- VERIFY( !ec );
+ fs::rename(p1, p1, ec); // no-op, but may fail
+ VERIFY( !ec || ec.value() == EEXIST );
VERIFY( is_regular_file(p1) );
ec.clear();
rename(p2, p1, ec);
VERIFY( ec );
- VERIFY( ec.value() == ENOENT );
+ VERIFY( ec.value() == ENOENT || ec.value() == EEXIST );
VERIFY( is_regular_file(p1) );
ec = bad_ec;
@@ -65,10 +65,11 @@ test01()
ec = bad_ec;
std::ofstream{p1}; // create file
fs::rename(p1, p2, ec);
- VERIFY( !ec );
- VERIFY( !exists(p1) );
+ VERIFY( !ec || ec.value() == EEXIST );
+ VERIFY( !exists(p1) || ec );
VERIFY( is_regular_file(p2) );
+ fs::remove(p1, ec);
fs::remove(p2, ec);
}
diff --git a/libstdc++-v3/testsuite/experimental/filesystem/operations/rename.cc b/libstdc++-v3/testsuite/experimental/filesystem/operations/rename.cc
index 520d48ef8d844..d2175652a79a8 100644
--- a/libstdc++-v3/testsuite/experimental/filesystem/operations/rename.cc
+++ b/libstdc++-v3/testsuite/experimental/filesystem/operations/rename.cc
@@ -47,8 +47,8 @@ test01()
ec = bad_ec;
std::ofstream{p1}; // create file
- fs::rename(p1, p1, ec); // no-op
- VERIFY( !ec );
+ fs::rename(p1, p1, ec); // no-op, but may fail
+ VERIFY( !ec || ec.value() == EEXIST );
VERIFY( is_regular_file(p1) );
ec.clear();
@@ -65,10 +65,11 @@ test01()
ec = bad_ec;
std::ofstream{p1}; // create file
fs::rename(p1, p2, ec);
- VERIFY( !ec );
- VERIFY( !exists(p1) );
+ VERIFY( !ec || ec.value() == EEXIST );
+ VERIFY( !exists(p1) || ec );
VERIFY( is_regular_file(p2) );
+ fs::remove(p1, ec);
fs::remove(p2, ec);
}
--
Alexandre Oliva, happy hacker https://FSFLA.org/blogs/lxo/
Free Software Activist GNU Toolchain Engineer
Disinformation flourishes because many people care deeply about injustice
but very few check the facts. Ask me about <https://stallmansupport.org>
next reply other threads:[~2022-06-22 6:24 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-22 6:24 Alexandre Oliva [this message]
2022-06-22 6:33 ` Sebastian Huber
2022-06-22 7:01 ` Alexandre Oliva
2022-06-22 10:41 ` Jonathan Wakely
2022-06-23 3:59 ` Alexandre Oliva
2022-06-23 6:26 ` Alexandre Oliva
2022-06-23 9:25 ` Jonathan Wakely
2022-06-23 11:21 ` Alexandre Oliva
2022-06-23 11:38 ` Jonathan Wakely
2022-06-23 12:41 ` Alexandre Oliva
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=orilot9pw4.fsf@lxoliva.fsfla.org \
--to=oliva@adacore.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=libstdc++@gcc.gnu.org \
/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
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).