public bool TryExtractAndDelete(IFileInfo file) { if (file.Extension == ".zip") { using (var archive = ZipArchive.Open(file.FullName)) { Console.WriteLine("Extracting ZIP archive " + file); ExtractArchiveTo(archive, file.DirectoryName); } file.Delete(); return(true); } else if (file.Extension == ".gz") { using (var archive = GZipArchive.Open(file.FullName)) { Console.WriteLine("Extracting GZ archive " + file); ExtractSingleEntryToFile(archive, Path.Combine(file.DirectoryName, Path.GetFileNameWithoutExtension(file.FullName))); } file.Delete(); return(true); } else if (file.Extension == ".tar") { // Using tar command because SharpCompress is unable to extract symbolic links ProcessRunner.Run("tar", new DirectoryInfo(Directory.GetCurrentDirectory()), "-hxf", file.FullName).Wait(); file.Delete(); return(true); } return(false); }
public void TearDown() { if (Environment.GetEnvironmentVariable("EAW_CI_TEST_STEAM_CLIENT") != "YES") { return; } string?itemIdString = Environment.GetEnvironmentVariable("EAW_CI_STEAM_WORKSHOP_ITEM_ID"); if (itemIdString == null) { return; } _steamAppIdFile.Delete(); _itemFolder.Delete(true); _descriptionFile.Delete(); Item item = GetItem(_itemId); DirectoryInfo directory = new DirectoryInfo(item.Directory); if (directory.Exists) { directory.Delete(true); } SteamClient.Shutdown(); }
public void CreateAndDeleteFile(IFileInfo fi) { FileStreamBase fs = fi.Create(); fs.Close(); fi.Delete(); }
protected byte[] DownloadCacheFile(IFileInfo target, IDocument remoteDocument, Transmission transmission, IFileSystemInfoFactory fsFactory) { if (!this.LoadCacheFile(target, remoteDocument, fsFactory)) { if (target.Exists) { target.Delete(); } } using (var hashAlg = new SHA1Reuse()) { using (var filestream = target.Open(FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None)) using (var downloader = ContentTaskUtils.CreateDownloader()) { try { downloader.DownloadFile(remoteDocument, filestream, transmission, hashAlg, (byte[] checksumUpdate, long length) => this.SaveCacheFile(target, remoteDocument, checksumUpdate, length, transmission)); if (this.TransmissionStorage != null) { this.TransmissionStorage.RemoveObjectByRemoteObjectId(remoteDocument.Id); } } catch (Exception ex) { transmission.FailedException = ex; throw; } } target.Refresh(); return(hashAlg.Hash); } }
/// <summary> Creates a new writer to the specified File object, to write data from /// the specified component. /// /// <p>The size of the image that is written to the file is the size of the /// component from which to get the data, specified by b, not the size of /// the source image (they differ if there is some sub-sampling).</p> /// /// </summary> /// <param name="out">The file where to write the data /// /// </param> /// <param name="imgSrc">The source from where to get the image data to write. /// /// </param> /// <param name="c">The index of the component from where to get the data. /// /// </param> public ImgWriterPGM(IFileInfo out_Renamed, BlkImgDataSrc imgSrc, int c) { // Check that imgSrc is of the correct type // Check that the component index is valid if (c < 0 || c >= imgSrc.NumComps) { throw new System.ArgumentException("Invalid number of components"); } // Check that imgSrc is of the correct type if (imgSrc.getNomRangeBits(c) > 8) { FacilityManager.getMsgLogger().println("Warning: Component " + c + " has nominal bitdepth " + imgSrc.getNomRangeBits(c) + ". Pixel values will be " + "down-shifted to fit bitdepth of 8 for PGM file", 8, 8); } // Initialize if (out_Renamed.Exists && !out_Renamed.Delete()) { throw new System.IO.IOException("Could not reset file"); } this.out_Renamed = SupportClass.RandomAccessFileSupport.CreateRandomAccessFile(out_Renamed, "rw"); src = imgSrc; this.c = c; w = imgSrc.ImgWidth; h = imgSrc.ImgHeight; fb = imgSrc.getFixedPoint(c); levShift = 1 << (imgSrc.getNomRangeBits(c) - 1); writeHeaderInfo(); }
public string StoreFile(IFileInfo file) { string hash = this.Algorithms.ComputeSha1(file); if (this.FileExists(hash)) { return(hash); } IFileInfo destination = this.GetFileInfo(hash); this.filesystem.Directory.CreateDirectory(destination.DirectoryName); this.filesystem.File.Copy(file.FullName, destination.FullName); // verify the hash, paranoid, but would detect some possible hardware issues string hashNew = this.Algorithms.ComputeSha1(destination); if (hash != hashNew) { destination.Delete(); throw new Exception("Copy not equal to original image (SHA1 hash differs)"); } destination.Attributes = destination.Attributes | System.IO.FileAttributes.ReadOnly; return(hashNew); }
public void TearDown() { _sourceFileInfo.Delete(); _targetFileInfo.Delete(); _directoryInfo.Delete(); Assert.IsFalse(_fileSystem.File.Exists(GetPlatformSourcePath())); Assert.IsFalse(_fileSystem.File.Exists(GetPlatformTargetPath())); }
private Task BackupFiles(IFileInfo sourceFile, string backupDirName, string summaryFile, CancellationToken cancellationToken) { IFileInfo targetFile = null; try { _logger.LogDebug($"Create SHA256 from file '{sourceFile.FullName}' ..."); var sourceFileHash = _hashGenerator.GenerateFrom(sourceFile); _logger.LogDebug($"SHA256 created: '{sourceFile.FullName}' -> {sourceFileHash}"); if (HasBackupFile(sourceFileHash)) { _logger.LogInformation($"File already backed up: '{sourceFile.FullName}'"); lock (_summaryFileLock) { AddFileInfo(summaryFile, sourceFile, sourceFileHash); } return(Task.CompletedTask); } var fileLock = _fileLocks.GetOrAdd(sourceFileHash, f => new object()); lock (fileLock) { var backupDir = _fileSystem.Path.Combine(_backupParam.TargetDir, backupDirName, sourceFileHash.Substring(0, 2)); if (CreateReferenceIfFileExists(sourceFile, backupDir, sourceFileHash)) { _logger.LogInformation($"Hash already exists, reference created: '{sourceFile.FullName}'"); lock (_summaryFileLock) { AddFileInfo(summaryFile, sourceFile, sourceFileHash); } return(Task.CompletedTask); } targetFile = _fileSystem.FileInfo.FromFileName(_fileSystem.Path.Combine(backupDir, sourceFileHash + ".7z")); targetFile.Directory.Create(); _logger.LogDebug($"Create backup from file '{sourceFile.FullName}' ..."); _sevenZipCli.Compress(sourceFile, targetFile, _backupParam.Password, cancellationToken); } _logger.LogInformation($"Backup created: '{sourceFile.FullName}' -> '{targetFile.FullName}'"); lock (_summaryFileLock) { AddFileInfo(summaryFile, sourceFile, sourceFileHash); } } catch (IOException ex) { _logger.LogError(ex, $"Create backup failed: '{sourceFile.FullName}'"); if (targetFile != null && targetFile.Exists) { targetFile.Delete(); } } return(Task.CompletedTask); }
public void TearDown() { _luaConfigFile.Delete(); if (_fileSystem.File.Exists("newfile.lua")) { _fileSystem.File.Delete("newfile.lua"); } }
public void DeleteFile(string hash) { IFileInfo source = this.GetFileInfo(hash); if (source.Exists) { source.Attributes = System.IO.FileAttributes.Normal; source.Delete(); } }
private void Delete(IFileInfo fileInfo) { if (fileInfo.Exists) { fileInfo.Delete(); LogInfo(SuccessMsg, fileInfo.FullName); } else { LogError(new FileNotFoundException(), NotExistMsg, fileInfo.FullName); } }
public void DeleteFile() { string fileName = "toBeDeleted"; string fullPath = Path.Combine(this.testFolder.FullName, fileName); IFileInfo fileInfo = Factory.CreateFileInfo(fullPath); using (fileInfo.Open(FileMode.CreateNew)) { } Assert.That(fileInfo.Exists, Is.True); fileInfo.Delete(); fileInfo.Refresh(); Assert.That(fileInfo.Exists, Is.False); }
/// <summary> Creates a new writer to the specified File object, to write data from /// the specified component. /// /// <p>The size of the image that is written to the file is the size of the /// component from which to get the data, specified by b, not the size of /// the source image (they differ if there is some sub-sampling).</p> /// /// <p>All the header informations are given by the BlkImgDataSrc source /// (component width, component height, bit-depth) and sign flag, which are /// provided to the constructor. The endianness is always big-endian (MSB /// first).</p> /// /// </summary> /// <param name="out">The file where to write the data /// /// </param> /// <param name="imgSrc">The source from where to get the image data to write. /// /// </param> /// <param name="c">The index of the component from where to get the data. /// /// </param> /// <param name="isSigned">Whether the datas are signed or not (needed only when /// writing header). /// /// </param> /// <seealso cref="DataBlk"> /// /// </seealso> public ImgWriterPGX(IFileInfo out_Renamed, BlkImgDataSrc imgSrc, int c, bool isSigned) { //Initialize this.c = c; if (out_Renamed.Exists && !out_Renamed.Delete()) { throw new System.IO.IOException("Could not reset file"); } this.out_Renamed = SupportClass.RandomAccessFileSupport.CreateRandomAccessFile(out_Renamed, "rw"); this.isSigned = isSigned; src = imgSrc; w = src.ImgWidth; h = src.ImgHeight; fb = imgSrc.getFixedPoint(c); bitDepth = src.getNomRangeBits(this.c); if ((bitDepth <= 0) || (bitDepth > 31)) { throw new System.IO.IOException("PGX supports only bit-depth between " + "1 and 31"); } if (bitDepth <= 8) { packBytes = 1; } else if (bitDepth <= 16) { packBytes = 2; } else { // <= 31 packBytes = 4; } // Writes PGX header System.String tmpString = "PG " + "ML " + ((this.isSigned)?"- ":"+ ") + bitDepth + " " + w + " " + h + "\n"; // component height byte[] tmpByte = System.Text.Encoding.UTF8.GetBytes(tmpString); for (int i = 0; i < tmpByte.Length; i++) { this.out_Renamed.WriteByte((byte)tmpByte[i]); } offset = tmpByte.Length; maxVal = this.isSigned?((1 << (src.getNomRangeBits(c) - 1)) - 1):((1 << src.getNomRangeBits(c)) - 1); minVal = this.isSigned?((-1) * (1 << (src.getNomRangeBits(c) - 1))):0; levShift = (this.isSigned)?0:1 << (src.getNomRangeBits(c) - 1); }
private void When_deleting_file_it_must_succeed() { // Arrange const string path = @"c:\some\file.txt"; IFileSystem fileSystem = new FakeFileSystemBuilder() .IncludingEmptyFile(path) .Build(); IFileInfo fileInfo = fileSystem.ConstructFileInfo(path); // Act fileInfo.Delete(); // Assert fileSystem.File.Exists(path).Should().BeFalse(); }
/// <summary> /// Compares two cataloged directories and lists all the files in the 'other' directory that duplicate files in the 'base' directory, with the option of deleting those files. /// </summary> private void compareCatalogsForDuplicates(IDirectoryInfo baseDirectory, Catalog baseCatalog, IDirectoryInfo otherDirectory, Catalog otherCatalog, bool shouldDelete) { List <FileInstance> fileInstancesToDelete = new List <FileInstance>(); foreach (FileInstance otherFileInstance in otherCatalog.FileInstances) { IReadOnlyList <FileInstance> matchingBaseFileInstances = baseCatalog.FindFiles(otherFileInstance.FileContentsHash); if (!matchingBaseFileInstances.Any()) { continue; } // [Todo]: If we found duplicates and we are going to delete the files, make sure their hashes are still up-to-date and identical in case the files were edited // though this doesn't make sense if being called from dir-compare since it is always up-to-date because the hashes were just taken. fileInstancesToDelete.Add(otherFileInstance); this.log(otherFileInstance.RelativePath); } this.log($"Found {fileInstancesToDelete.Count} files in '{otherDirectory}' duplicating those in '{baseDirectory}'."); if (shouldDelete && fileInstancesToDelete.Any()) { this.outputWriter.WriteLine($"Really delete? <yes|no>"); if (!string.Equals(this.inputReader.ReadLine(), "yes", StringComparison.OrdinalIgnoreCase)) { throw new OperationCanceledException("Aborting, nothing deleted."); } int deletedCount = 0; try { foreach (FileInstance fileInstance in fileInstancesToDelete) { string fullPath = this.fileSystem.Path.Combine(otherDirectory.FullName, fileInstance.RelativePath); IFileInfo fileInfo = this.fileSystem.FileInfo.FromFileName(fullPath); fileInfo.Attributes = System.IO.FileAttributes.Normal; fileInfo.Delete(); deletedCount++; } } finally { this.log($"Deleted {deletedCount} files."); } } }
public void BackupFile(IFileInfo file) { IDirectoryInfo dailyBackupDirectoryPath = CreateDailyBackupDirectory(); string backupFilePath = Path.Combine(dailyBackupDirectoryPath.FullName, file.Name); if (_fileSystem.File.Exists(backupFilePath)) { file.Delete(); string warnMessage = $"File: {backupFilePath.GetFileName()} already exists in Backup-Directory"; Log.Logger.Warn(warnMessage); } else { _fileSystem.File.Move(file.FullName, backupFilePath); Log.Logger.Info($"File: {backupFilePath.GetFileName()} moved to Backup-Directory"); } }
/// <summary> Constructor. Always needs a size for the buffer. /// /// </summary> /// <param name="file">The file associated with the buffer /// /// </param> /// <param name="mode">"r" for read, "rw" or "rw+" for read and write mode ("rw+" /// opens the file for update whereas "rw" removes it /// before. So the 2 modes are different only if the file /// already exists). /// /// </param> /// <param name="bufferSize">The number of bytes to buffer /// /// </param> /// <exception cref="java.io.IOException">If an I/O error ocurred. /// /// </exception> protected internal BufferedRandomAccessFile(IFileInfo file, System.String mode, int bufferSize) { fileName = file.Name; if (mode.Equals("rw") || mode.Equals("rw+")) { // mode read / write isReadOnly = false; if (mode.Equals("rw")) { if (file.Exists && !file.Delete()) { throw new System.IO.IOException("Could not delete existing file"); } } mode = "rw"; } theFile = SupportClass.RandomAccessFileSupport.CreateRandomAccessFile(file, mode); byteBuffer = new byte[bufferSize]; readNewBuffer(0); }
private void When_changing_file_existence_it_must_not_refresh_automatically() { // Arrange const string path = @"c:\some\file.txt"; IFileSystem fileSystem = new FakeFileSystemBuilder() .IncludingEmptyFile(path) .Build(); IFileInfo fileInfo = fileSystem.ConstructFileInfo(path); bool beforeFound = fileInfo.Exists; // Act fileInfo.Delete(); // Assert bool afterFound = fileInfo.Exists; beforeFound.Should().BeTrue(); afterFound.Should().BeTrue(); }
/// <summary> Creates a new writer to the specified File object, to write data from /// the specified component. /// /// <p>The three components that will be written as R, G and B must be /// specified through the b1, b2 and b3 arguments.</p> /// /// </summary> /// <param name="out">The file where to write the data /// /// </param> /// <param name="imgSrc">The source from where to get the image data to write. /// /// </param> /// <param name="n1">The index of the first component from where to get the data, /// that will be written as the red channel. /// /// </param> /// <param name="n2">The index of the second component from where to get the data, /// that will be written as the green channel. /// /// </param> /// <param name="n3">The index of the third component from where to get the data, /// that will be written as the green channel. /// /// </param> /// <seealso cref="DataBlk"> /// /// </seealso> public ImgWriterPPM(IFileInfo out_Renamed, BlkImgDataSrc imgSrc, int n1, int n2, int n3) { // Check that imgSrc is of the correct type // Check that the component index is valid if ((n1 < 0) || (n1 >= imgSrc.NumComps) || (n2 < 0) || (n2 >= imgSrc.NumComps) || (n3 < 0) || (n3 >= imgSrc.NumComps) || (imgSrc.getNomRangeBits(n1) > 8) || (imgSrc.getNomRangeBits(n2) > 8) || (imgSrc.getNomRangeBits(n3) > 8)) { throw new System.ArgumentException("Invalid component indexes"); } // Initialize w = imgSrc.getCompImgWidth(n1); h = imgSrc.getCompImgHeight(n1); // Check that all components have same width and height if (w != imgSrc.getCompImgWidth(n2) || w != imgSrc.getCompImgWidth(n3) || h != imgSrc.getCompImgHeight(n2) || h != imgSrc.getCompImgHeight(n3)) { throw new System.ArgumentException("All components must have the" + " same dimensions and no" + " subsampling"); } w = imgSrc.ImgWidth; h = imgSrc.ImgHeight; // Continue initialization if (out_Renamed.Exists && !out_Renamed.Delete()) { throw new System.IO.IOException("Could not reset file"); } this.out_Renamed = SupportClass.RandomAccessFileSupport.CreateRandomAccessFile(out_Renamed, "rw"); src = imgSrc; cps[0] = n1; cps[1] = n2; cps[2] = n3; fb[0] = imgSrc.getFixedPoint(n1); fb[1] = imgSrc.getFixedPoint(n2); fb[2] = imgSrc.getFixedPoint(n3); levShift[0] = 1 << (imgSrc.getNomRangeBits(n1) - 1); levShift[1] = 1 << (imgSrc.getNomRangeBits(n2) - 1); levShift[2] = 1 << (imgSrc.getNomRangeBits(n3) - 1); writeHeaderInfo(); }
private void When_deleting_file_it_must_update_cache_on_refresh() { // Arrange const string path = @"c:\some\file.txt"; IFileSystem fileSystem = new FakeFileSystemBuilder() .IncludingEmptyFile(path) .Build(); IFileInfo fileInfo = fileSystem.ConstructFileInfo(path); bool beforeFound = fileInfo.Exists; fileInfo.Delete(); // Act fileInfo.Refresh(); // Assert bool afterFound = fileInfo.Exists; beforeFound.Should().BeTrue(); afterFound.Should().BeFalse(); }
/// <summary> Creates a new writer to the specified File object, to write data from /// the specified component. /// /// <p>The size of the image that is written to the file is the size of the /// component from which to get the data, specified by b, not the size of /// the source image (they differ if there is some sub-sampling).</p> /// /// <p>All the header informations are given by the BlkImgDataSrc source /// (component width, component height, bit-depth) and sign flag, which are /// provided to the constructor. The endianness is always big-endian (MSB /// first).</p> /// /// </summary> /// <param name="out">The file where to write the data /// /// </param> /// <param name="imgSrc">The source from where to get the image data to write. /// /// </param> /// <param name="c">The index of the component from where to get the data. /// /// </param> /// <param name="isSigned">Whether the datas are signed or not (needed only when /// writing header). /// /// </param> /// <seealso cref="DataBlk"> /// /// </seealso> public ImgWriterPGX(IFileInfo out_Renamed, BlkImgDataSrc imgSrc, int c, bool isSigned) { //Initialize this.c = c; if (out_Renamed.Exists && !out_Renamed.Delete()) { throw new System.IO.IOException("Could not reset file"); } this.out_Renamed = SupportClass.RandomAccessFileSupport.CreateRandomAccessFile(out_Renamed, "rw"); this.isSigned = isSigned; src = imgSrc; w = src.ImgWidth; h = src.ImgHeight; fb = imgSrc.getFixedPoint(c); bitDepth = src.getNomRangeBits(this.c); if ((bitDepth <= 0) || (bitDepth > 31)) { throw new System.IO.IOException("PGX supports only bit-depth between " + "1 and 31"); } if (bitDepth <= 8) { packBytes = 1; } else if (bitDepth <= 16) { packBytes = 2; } else { // <= 31 packBytes = 4; } // Writes PGX header System.String tmpString = "PG " + "ML " + ((this.isSigned)?"- ":"+ ") + bitDepth + " " + w + " " + h + "\n"; // component height byte[] tmpByte = System.Text.Encoding.UTF8.GetBytes(tmpString); for (int i = 0; i < tmpByte.Length; i++) { this.out_Renamed.WriteByte((byte) tmpByte[i]); } offset = tmpByte.Length; maxVal = this.isSigned?((1 << (src.getNomRangeBits(c) - 1)) - 1):((1 << src.getNomRangeBits(c)) - 1); minVal = this.isSigned?((- 1) * (1 << (src.getNomRangeBits(c) - 1))):0; levShift = (this.isSigned)?0:1 << (src.getNomRangeBits(c) - 1); }
public void Delete() { _file.Delete(); }
protected byte[] DownloadCacheFile(IFileInfo target, IDocument remoteDocument, Transmission transmission, IFileSystemInfoFactory fsFactory) { if (!this.LoadCacheFile(target, remoteDocument, fsFactory)) { if (target.Exists) { target.Delete(); } } using (var hashAlg = new SHA1Reuse()) { using (var filestream = target.Open(FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None)) using (var downloader = ContentTaskUtils.CreateDownloader()) { try { downloader.DownloadFile(remoteDocument, filestream, transmission, hashAlg, (byte[] checksumUpdate, long length) => this.SaveCacheFile(target, remoteDocument, checksumUpdate, length, transmission)); if (this.TransmissionStorage != null) { this.TransmissionStorage.RemoveObjectByRemoteObjectId(remoteDocument.Id); } } catch (Exception ex) { transmission.FailedException = ex; throw; } } target.Refresh(); return hashAlg.Hash; } }
private bool LoadCacheFile(IFileInfo target, IDocument remoteDocument, IFileSystemInfoFactory fsFactory) { if (this.TransmissionStorage == null) { return false; } IFileTransmissionObject obj = this.TransmissionStorage.GetObjectByRemoteObjectId(remoteDocument.Id); if (obj == null) { return false; } IFileInfo localFile = fsFactory.CreateFileInfo(obj.LocalPath); if (!localFile.Exists) { return false; } if (obj.LastChangeToken != remoteDocument.ChangeToken || localFile.Length != obj.LastContentSize) { localFile.Delete(); return false; } try { byte[] localHash; using (var f = localFile.Open(FileMode.Open, FileAccess.Read, FileShare.None)) { localHash = SHA1Managed.Create().ComputeHash(f); } if (!localHash.SequenceEqual(obj.LastChecksum)) { localFile.Delete(); return false; } if (target.FullName != obj.LocalPath) { if (target.Exists) { Guid? uuid = target.Uuid; if (uuid != null) { localFile.Uuid = uuid; } target.Delete(); } localFile.MoveTo(target.FullName); target.Refresh(); } return true; } catch (Exception) { localFile.Delete(); return false; } }
/// <summary> Constructor. Always needs a size for the buffer. /// /// </summary> /// <param name="file">The file associated with the buffer /// /// </param> /// <param name="mode">"r" for read, "rw" or "rw+" for read and write mode ("rw+" /// opens the file for update whereas "rw" removes it /// before. So the 2 modes are different only if the file /// already exists). /// /// </param> /// <param name="bufferSize">The number of bytes to buffer /// /// </param> /// <exception cref="IOException">If an I/O error ocurred. /// /// </exception> protected internal BufferedRandomAccessFile(IFileInfo file, System.String mode, int bufferSize) { fileName = file.Name; if (mode.Equals("rw") || mode.Equals("rw+")) { // mode read / write isReadOnly = false; if (mode.Equals("rw")) { if (file.Exists && !file.Delete()) { throw new System.IO.IOException("Could not delete existing file"); } } mode = "rw"; } theFile = SupportClass.RandomAccessFileSupport.CreateRandomAccessFile(file, mode); byteBuffer = new byte[bufferSize]; readNewBuffer(0); }
public void Delete() { _info.Delete(); }
public void Delete() { _fileInfo.Delete(); }
private bool LoadCacheFile(IFileInfo target, IDocument remoteDocument, IFileSystemInfoFactory fsFactory) { if (this.TransmissionStorage == null) { return(false); } IFileTransmissionObject obj = this.TransmissionStorage.GetObjectByRemoteObjectId(remoteDocument.Id); if (obj == null) { return(false); } IFileInfo localFile = fsFactory.CreateFileInfo(obj.LocalPath); if (!localFile.Exists) { return(false); } if (obj.LastChangeToken != remoteDocument.ChangeToken || localFile.Length != obj.LastContentSize) { localFile.Delete(); return(false); } try { byte[] localHash; using (var f = localFile.Open(FileMode.Open, FileAccess.Read, FileShare.None)) { localHash = SHA1Managed.Create().ComputeHash(f); } if (!localHash.SequenceEqual(obj.LastChecksum)) { localFile.Delete(); return(false); } if (target.FullName != obj.LocalPath) { if (target.Exists) { Guid?uuid = target.Uuid; if (uuid != null) { localFile.Uuid = uuid; } target.Delete(); } localFile.MoveTo(target.FullName); target.Refresh(); } return(true); } catch (Exception) { localFile.Delete(); return(false); } }