Skip to contentSkip to conversation

utils: is_path_on_nfs: strip not existing path

PATCH New Jose Quaresma 1 participant 1 message Feb 12

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 utils: is_path_on_nfs: strip not existing path

From: Jose Quaresma <[email protected]>

When the user provide a path that does not exist it fails with:
| stat: cannot read file system information for '/path/to/my/hashserve': No such file or directory

We can strip the non exising part in the path and pass just that to the stat.

---
 lib/bb/utils.py | 5 +++++
 1 file changed, 5 insertions(+)
lib/bb/utils.py +5 -0
index 974611bc7..b2bda08cb 100644
@@ -2269,6 +2269,11 @@ def is_path_on_nfs(path):
     """
     Returns True if ``path`` argument is on a NFS mount.
     """
+    # strip not existing path
+    if os.path.isabs(path):
+        while not os.path.exists(path):
+            path = os.path.dirname(path)
+
     import bb.process
     fstype = bb.process.run("stat -f -c %T {}".format(path))[0].strip()
     return fstype == "nfs"
Signature · 1 line
2.53.0