/// <summary> /// Remove a file from quarantine and delete its associated metadata. /// </summary> /// <param name="file"></param> public static void RemoveFile(QuarantineFileItem file, bool metadataOnly) { try { if (!metadataOnly) { File.Delete(file.AbsolutePath); } } catch (Exception ex) { logger.Error(ex, "Error deleting file from quarantine: {0}", file.AbsolutePath); throw; } try { File.Delete(file.MetadataFilePath); } catch (Exception ex) { logger.Error(ex, "Error deleting quarantine metadata: {0}", file.MetadataFilePath); throw; } }
/// <summary> /// Move a file from a location on disk into the quarantine folder. /// </summary> /// <param name="file">FileInfo instance representing the file to be moved.</param> public static void ImportFile(FileInfo file) { var quarantineFile = new QuarantineFileItem(file); try { File.Move(file.FullName, quarantineFile.AbsolutePath); } catch (Exception ex) { logger.Error( ex, string.Format("Quarantine file move failed for '{0}'", file.FullName)); throw; } try { /* Serialize and save the metadata file. */ quarantineFile.Save(AppFolders.QuarantineFolder); } catch (Exception ex) { logger.Error( ex, string.Format("Quarantine metadata file creation failed in '{0}'", AppFolders.QuarantineFolder)); logger.Debug("Moving file back to {0}", file.FullName); File.Move(quarantineFile.AbsolutePath, file.FullName); logger.Debug("File restore succeeded"); throw; } }
public static void RestoreFile(QuarantineFileItem file) { try { File.Move(file.AbsolutePath, file.OriginalAbsolutePath); File.Delete(file.MetadataFilePath); } catch (Exception ex) { logger.Error( ex, string.Format("Quarantine removal failed for '{0}'", file.Name)); throw; } }