From f94bdb4ead271c17633d2405e63990fb182f4e0c Mon Sep 17 00:00:00 2001 From: Patrick Donnelly Date: Wed, 12 Mar 2025 10:33:02 -0400 Subject: [PATCH] libcephfs: getcwd after chdir for API constraint libcephfs semantics require that the old path to the cwd be returned when getcwd is encounters an unlinked directory in the current working directory. Signed-off-by: Patrick Donnelly (cherry picked from commit c7c5089ff95d6c68e009686bf4ff74772ad4ff67) --- src/libcephfs.cc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/libcephfs.cc b/src/libcephfs.cc index f1188dab080b8..f492562c771e1 100644 --- a/src/libcephfs.cc +++ b/src/libcephfs.cc @@ -322,7 +322,15 @@ public: int chdir(const char *to, const UserPerm& perms) { - return client->chdir(to, perms); + int rc = client->chdir(to, perms); + if (rc == 0) { + /* Current API requires "cwd" to be refreshed after every chdir so that + * getcwd on an unlinked cwd will still return the old path. Note: + * Client::getcwd now returns an error but leaves the "cwd" string + * unmodified for this purpose. */ + client->getcwd(cwd, perms); + } + return rc; } CephContext *get_ceph_context() const { -- 2.39.5