Example #1
0
 def copy_file(self, src_path, dst_path):
     if os.path.exists(dst_path):
         return
     try:
         filelink.create(src_path, dst_path, filelink.HARDLINK)
     except OSError:
         shutil.copyfile(src_path, dst_path)
Example #2
0
    def copy_file(self, src_path, dst_path):
        # TODO check drives if are the same to check if cas hardlink
        dirname = os.path.dirname(dst_path)

        try:
            os.makedirs(dirname)
            self.log.debug("Folder(s) created: \"{}\"".format(dirname))
        except OSError as exc:
            if exc.errno != errno.EEXIST:
                self.log.error("An unexpected error occurred.", exc_info=True)
                raise

            self.log.debug("Folder already exists: \"{}\"".format(dirname))

        self.log.debug("Copying file \"{}\" to \"{}\"".format(
            src_path, dst_path
        ))

        # First try hardlink and copy if paths are cross drive
        try:
            filelink.create(src_path, dst_path, filelink.HARDLINK)
            # Return when successful
            return

        except OSError as exc:
            # re-raise exception if different than cross drive path
            if exc.errno != errno.EXDEV:
                raise

        shutil.copy(src_path, dst_path)
Example #3
0
    def hardlink_file(self, src, dst):
        dirname = os.path.dirname(dst)
        try:
            os.makedirs(dirname)
        except OSError as e:
            if e.errno == errno.EEXIST:
                pass
            else:
                self.log.critical("An unexpected error occurred.")
                raise

        filelink.create(src, dst, filelink.HARDLINK)
Example #4
0
    def hardlink_file(self, src, dst):
        if os.path.isfile(dst):
            self.log.warning("File exists, skip creating hardlink: %s" % dst)
            return

        dirname = os.path.dirname(dst)
        try:
            os.makedirs(dirname)
        except OSError as e:
            if e.errno == errno.EEXIST:
                pass
            else:
                self.log.critical("An unexpected error occurred.")
                raise

        filelink.create(src, dst, filelink.HARDLINK)
Example #5
0
        def copy(src, dst):
            dirname = os.path.dirname(dst)
            try:
                os.makedirs(dirname)
            except OSError as e:
                if e.errno == errno.EEXIST:
                    pass
                else:
                    self.log.critical("An unexpected error occurred.")
                    raise

            try:
                filelink.create(src, dst)
                self.log.info("Linking %s -> %s" % (src, dst))
            except Exception:
                # Revert to a normal copy
                # TODO(marcus): Once filelink is proven stable,
                # improve upon or remove this fallback.
                shutil.copy(src, dst)
                self.log.info("Linking failed, copying %s -> %s" % (src, dst))
    def hardlink_file(self, src, dst):
        dirname = os.path.dirname(dst)

        # make sure the destination folder exist
        try:
            os.makedirs(dirname)
        except OSError as e:
            if e.errno == errno.EEXIST:
                pass
            else:
                self.log.critical("An unexpected error occurred.")
                six.reraise(*sys.exc_info())

        # create hardlined file
        try:
            filelink.create(src, dst, filelink.HARDLINK)
        except OSError as e:
            if e.errno == errno.EEXIST:
                pass
            else:
                self.log.critical("An unexpected error occurred.")
                six.reraise(*sys.exc_info())