def copy_config_files()

in src/extension/src/ActionHandler.py [0:0]


    def copy_config_files(self, src, dst, raise_if_not_copied=False):
        """ Copies files, required by the extension, from the given config/src folder """
        self.logger.log("Copying only the files required by the extension for current and future operations. Any other files created by the Guest agent or extension, such as configuration settings, handlerstate, etc, that are not required in future, will not be copied.")

        # get all the required files to be copied from parent dir
        files_to_copy = []
        for root, dirs, files in os.walk(src):
            for file_name in files:
                if Constants.EXT_STATE_FILE not in file_name and Constants.CORE_STATE_FILE not in file_name and ".bak" not in file_name:
                    continue
                file_path = os.path.join(root, file_name)
                files_to_copy.append(file_path)
        self.logger.log("List of files to be copied from preceding extension version to the current: [Files to be copied={0}]".format(str(files_to_copy)))

        # copy each file
        for file_to_copy in files_to_copy:
            for i in range(0, Constants.MAX_IO_RETRIES):
                try:
                    self.logger.log("Copying file. [Source={0}] [Destination={1}]".format(str(file_to_copy), str(dst)))
                    shutil.copy(file_to_copy, dst)
                    break
                except Exception as error:
                    if i < Constants.MAX_IO_RETRIES - 1:
                        time.sleep(i + 1)
                    else:
                        error_msg = "Failed to copy file after {0} tries. [Source={1}] [Destination={2}] [Exception={3}]".format(Constants.MAX_IO_RETRIES, str(file_to_copy), str(dst), repr(error))
                        self.logger.log_error(error_msg)
                        if raise_if_not_copied:
                            raise Exception(error_msg)

        self.logger.log("All required files from the preceding extension version were copied to current one")