]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
libcephfs: getcwd after chdir for API constraint
authorPatrick Donnelly <pdonnell@ibm.com>
Wed, 12 Mar 2025 14:33:02 +0000 (10:33 -0400)
committerPatrick Donnelly <pdonnell@ibm.com>
Thu, 13 Mar 2025 14:07:13 +0000 (10:07 -0400)
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 <pdonnell@ibm.com>
src/libcephfs.cc

index 9fc20f731c523442b0112a6978ec99377a3a57fa..ce1b6ccd0b05af277b067167f802f5b38f09b72d 100644 (file)
@@ -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 {