diff options
Diffstat (limited to 'cobbler/utils.py')
-rw-r--r-- | cobbler/utils.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/cobbler/utils.py b/cobbler/utils.py index 72b438fc..18535638 100644 --- a/cobbler/utils.py +++ b/cobbler/utils.py @@ -958,6 +958,8 @@ def bindmount(src,dst): except: if not os.access(src,os.R_OK): raise CX(_("Cannot read: %s") % src) + if not os.access(dst,os.R_OK): + raise CX(_("Cannot read: %s") % dst) if not os.path.samefile(src,dst): # accomodate for the possibility that we already copied # the file as a symlink/hardlink @@ -965,6 +967,49 @@ def bindmount(src,dst): # traceback.print_exc() # raise CX(_("Error bind-mounting %(src)s to %(dst)s") % { "src" : src, "dst" : dst}) +def check_openfiles(src): + """ + Used to check for open files on a mounted partition. + """ + try: + if not os.path.isdir(src): + raise CX(_("Error in check_openfiles: the source (%s) must be a directory") % src) + cmd = [ "/usr/sbin/lsof", "+D", src, "-Fn", "|", "wc", "-l" ] + handle = sub_process.Popen(cmd, shell=True, stdout=sub_process.PIPE, close_fds=True) + out = handle.stdout + results = out.read() + return int(results) + except: + if not os.access(src,os.R_OK): + raise CX(_("Cannot read: %s") % src) + if not os.path.samefile(src,dst): + # accomodate for the possibility that we already copied + # the file as a symlink/hardlink + raise + # traceback.print_exc() + # raise CX(_("Error bind-mounting %(src)s to %(dst)s") % { "src" : src, "dst" : dst}) + +def umount(src): + """ + Used for unmounting things created by bindmount + """ + try: + if not os.path.isdir(src): + raise CX(_("Error in umount: the source (%s) must be a directory") % src) + cmd = [ "/bin/umount", "--force", src ] + rc = sub_process.call(cmd, shell=False, close_fds=True) + return rc + except: + if not os.access(src,os.R_OK): + raise CX(_("Cannot read: %s") % src) + if not os.path.samefile(src,dst): + # accomodate for the possibility that we already copied + # the file as a symlink/hardlink + raise + # traceback.print_exc() + # raise CX(_("Error bind-mounting %(src)s to %(dst)s") % { "src" : src, "dst" : dst}) + + def copyfile_pattern(pattern,dst,require_match=True,symlink_ok=False,api=None, verbose=False): files = glob.glob(pattern) if require_match and not len(files) > 0: |