From: Alfredo Deza Date: Fri, 3 Nov 2017 18:34:39 +0000 (-0400) Subject: ceph-volume simple.system add a helper to check if a file is a binary or not X-Git-Tag: v13.0.1~256^2~38 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=7bf8676045b4f966b60cdadf4d5af1c89fca69ae;p=ceph.git ceph-volume simple.system add a helper to check if a file is a binary or not Signed-off-by: Alfredo Deza --- diff --git a/src/ceph-volume/ceph_volume/util/system.py b/src/ceph-volume/ceph_volume/util/system.py index 940b9dbdc5d3..d580a4c28f08 100644 --- a/src/ceph-volume/ceph_volume/util/system.py +++ b/src/ceph-volume/ceph_volume/util/system.py @@ -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,