]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-volume simple.system add a helper to check if a file is a binary or not
authorAlfredo Deza <adeza@redhat.com>
Fri, 3 Nov 2017 18:34:39 +0000 (14:34 -0400)
committerAlfredo Deza <adeza@redhat.com>
Mon, 13 Nov 2017 15:20:10 +0000 (10:20 -0500)
Signed-off-by: Alfredo Deza <adeza@redhat.com>
(cherry picked from commit 7bf8676045b4f966b60cdadf4d5af1c89fca69ae)

src/ceph-volume/ceph_volume/util/system.py

index 940b9dbdc5d371535d6bef3e26d6cd92e802b70c..d580a4c28f08f33cb7b5fe12fdf6d04ce8c1be90 100644 (file)
@@ -69,6 +69,18 @@ def chown(path, recursive=True):
         os.chown(path, uid, gid)
 
 
+def is_binary(path):
+    """
+    Detect if a file path is a binary or not. Will falsely report as binary
+    when utf-16 encoded. In the ceph universe there is no such risk (yet)
+    """
+    with open(path, 'rb') as fp:
+        contents = fp.read(8192)
+    if b'\x00' in contents:  # a null byte may signal binary
+        return True
+    return False
+
+
 class tmp_mount(object):
     """
     Temporarily mount a device on a temporary directory,