public void DeleteFile(string path) { logger.Debug("Attempting to send '{0}' to recycling bin", path); var recyclingBin = _configService.RecycleBin; if (String.IsNullOrWhiteSpace(recyclingBin)) { logger.Info("Recycling Bin has not been configured, deleting permanently."); if (!OsInfo.IsMono) { logger.Debug(_diskProvider.GetFileAttributes(path)); } _diskProvider.DeleteFile(path); logger.Debug("File has been permanently deleted: {0}", path); } else { var destination = Path.Combine(recyclingBin, new FileInfo(path).Name); logger.Debug("Moving '{0}' to '{1}'", path, destination); _diskProvider.MoveFile(path, destination); _diskProvider.FileSetLastWriteTimeUtc(destination, DateTime.UtcNow); logger.Debug("File has been moved to the recycling bin: {0}", destination); } }
public void DeleteFile(string path, string subfolder = "") { _logger.Debug("Attempting to send '{0}' to recycling bin", path); var recyclingBin = _configService.RecycleBin; if (string.IsNullOrWhiteSpace(recyclingBin)) { _logger.Info("Recycling Bin has not been configured, deleting permanently. {0}", path); if (OsInfo.IsWindows) { _logger.Debug(_diskProvider.GetFileAttributes(path)); } _diskProvider.DeleteFile(path); _logger.Debug("File has been permanently deleted: {0}", path); } else { var fileInfo = new FileInfo(path); var destinationFolder = Path.Combine(recyclingBin, subfolder); var destination = Path.Combine(destinationFolder, fileInfo.Name); _diskProvider.CreateFolder(destinationFolder); var index = 1; while (_diskProvider.FileExists(destination)) { index++; if (fileInfo.Extension.IsNullOrWhiteSpace()) { destination = Path.Combine(destinationFolder, fileInfo.Name + "_" + index); } else { destination = Path.Combine(destinationFolder, Path.GetFileNameWithoutExtension(fileInfo.Name) + "_" + index + fileInfo.Extension); } } try { _logger.Debug("Moving '{0}' to '{1}'", path, destination); _diskTransferService.TransferFile(path, destination, TransferMode.Move); } catch (IOException e) { _logger.Error(e, "Unable to move '{0}' to the recycling bin: '{1}'", path, destination); throw; } //TODO: Better fix than this for non-Windows? if (OsInfo.IsWindows) { _diskProvider.FileSetLastWriteTime(destination, DateTime.UtcNow); } _logger.Debug("File has been moved to the recycling bin: {0}", destination); } }
public void DeleteFile(string path) { logger.Debug("Attempting to send '{0}' to recycling bin", path); var recyclingBin = _configService.RecycleBin; if (String.IsNullOrWhiteSpace(recyclingBin)) { logger.Info("Recycling Bin has not been configured, deleting permanently."); if (OsInfo.IsWindows) { logger.Debug(_diskProvider.GetFileAttributes(path)); } _diskProvider.DeleteFile(path); logger.Debug("File has been permanently deleted: {0}", path); } else { var fileInfo = new FileInfo(path); var destination = Path.Combine(recyclingBin, fileInfo.Name); var index = 1; while (_diskProvider.FileExists(destination)) { index++; if (fileInfo.Extension.IsNullOrWhiteSpace()) { destination = Path.Combine(recyclingBin, fileInfo.Name + "_" + index); } else { destination = Path.Combine(recyclingBin, Path.GetFileNameWithoutExtension(fileInfo.Name) + "_" + index + fileInfo.Extension); } } logger.Debug("Moving '{0}' to '{1}'", path, destination); _diskProvider.MoveFile(path, destination, true); //TODO: Better fix than this for non-Windows? if (OsInfo.IsWindows) { _diskProvider.FileSetLastWriteTimeUtc(destination, DateTime.UtcNow); } logger.Debug("File has been moved to the recycling bin: {0}", destination); } }