func TryClearExtensionScriptsDirectoriesAndSettingsFiles()

in pkg/linuxutils/linuxutils.go [15:30]


func TryClearExtensionScriptsDirectoriesAndSettingsFiles(ctx *log.Context, scriptsDirectory string, runtimeSettingsDirectory string, extensionName string, runtimeSettingsRegexFormatWithAnyExtName string) error {
	// It is important to call both methods first and then handle the errors or unexpected files could remain in the VM.
	// E.g., If nothing was dowloaded to the VM, the directory won't exist and thus the `TryDeleteDirectories` will return an error.
	dirErr := TryDeleteDirectories(ctx, filepath.Join(scriptsDirectory, extensionName))
	filesErr := tryClearRegexMatchingFiles(ctx, runtimeSettingsDirectory, runtimeSettingsRegexFormatWithAnyExtName, true)

	if dirErr != nil && filesErr != nil {
		return fmt.Errorf("failed to delete dirs: %w; failed to delete settings: %w", dirErr, filesErr)
	} else if dirErr != nil {
		return errors.Wrap(dirErr, "could not delete extension scripts directories")
	} else if filesErr != nil {
		return errors.Wrap(filesErr, "could not delete runtime settings files")
	}

	return nil
}