/// <summary> /// Replaces the contents of a specified destinationFile with the file described by the current IFileInfo /// object, deleting the original file, and creating a backup of the replaced file. /// Also specifies whether to ignore merge errors. /// </summary> /// <param name="destinationFile">Destination file.</param> /// <param name="destinationBackupFileName">Destination backup file name.</param> /// <param name="ignoreMetadataErrors"><c>true</c> to ignore merge errors (such as attributes and ACLs) from the replaced file to the replacement file; otherwise <c>false</c>.</param> /// <returns>A IFileInfo object that encapsulates information about the file described by the destFileName parameter.</returns> public IFileInfo Replace(IFileInfo destinationFile, IFileInfo destinationBackupFileName, bool ignoreMetadataErrors) { #if __MonoCS__ var reader = new ExtendedAttributeReaderUnix(); var oldSourceEAs = new Dictionary <string, string>(); var oldTargetEAs = new Dictionary <string, string>(); if (reader.IsFeatureAvailable(this.FullName)) { foreach (var key in reader.ListAttributeKeys(this.FullName)) { oldSourceEAs.Add(key, this.GetExtendedAttribute(key)); } foreach (var key in reader.ListAttributeKeys(destinationFile.FullName)) { oldTargetEAs.Add(key, destinationFile.GetExtendedAttribute(key)); } } #endif var result = new FileInfoWrapper(this.original.Replace(destinationFile.FullName, destinationBackupFileName.FullName, ignoreMetadataErrors)); #if __MonoCS__ foreach (var entry in oldSourceEAs) { result.SetExtendedAttribute(entry.Key, entry.Value, true); } foreach (var entry in oldTargetEAs) { destinationBackupFileName.SetExtendedAttribute(entry.Key, entry.Value, true); } #endif return(result); }
public void GetNullAttributeFromNewFile() { using (File.Create(path)); string key = "test"; var reader = new ExtendedAttributeReaderUnix(); Assert.That(reader.GetExtendedAttribute(path, key), Is.Null); }
public void SetAttributeToFile() { using (File.Create(path)); string key = "test"; string value = "value"; var reader = new ExtendedAttributeReaderUnix(); reader.SetExtendedAttribute(path, key, value); Assert.That(reader.GetExtendedAttribute(path, key).Equals(value)); }
public void SetUp() { var config = ITUtils.GetConfig(); string localPath = config[1].ToString(); path = Path.Combine(localPath, Path.GetRandomFileName()); var reader = new ExtendedAttributeReaderUnix(); if(!reader.IsFeatureAvailable(localPath)) { Assert.Ignore("Extended Attribute not available on this machine"); } }
public void RemoveExtendedAttributeOnNonExistingFileThrowsFileNotFoundException() { string key = "test"; var reader = new ExtendedAttributeReaderUnix(); try{ reader.RemoveExtendedAttribute(path, key); } catch (FileNotFoundException) { return; } Assert.Fail("FileNotFoundException not thrown"); }
public void SetExtendedAttributeDoesNotChangesModificationDate() { using (File.Create(path)); File.SetLastWriteTimeUtc(path, DateTime.UtcNow.AddDays(1)); DateTime futureDate = File.GetLastWriteTimeUtc(path); string key = "test"; string value = "value"; var reader = new ExtendedAttributeReaderUnix(); reader.SetExtendedAttribute(path, key, value, true); Assert.That(File.GetLastWriteTimeUtc(path), Is.EqualTo(futureDate)); }
public void SetExtendedAttributeOnNonExistingFileThrowsFileNotFoundException() { string key = "test"; var reader = new ExtendedAttributeReaderUnix(); Assert.Throws<FileNotFoundException>(() => reader.SetExtendedAttribute(path, key, null)); }
public void RemoveNonExistingAttributeFromFolder() { Directory.CreateDirectory(path); string key = "test"; var reader = new ExtendedAttributeReaderUnix(); reader.RemoveExtendedAttribute(path, key); Assert.That(reader.GetExtendedAttribute(path, key), Is.Null); }
public void CheckAvailableOnPath() { var reader = new ExtendedAttributeReaderUnix(); reader.IsFeatureAvailable(Environment.CurrentDirectory); }
public void ListAttributesOfFolder() { Directory.CreateDirectory(path); string key = "test"; string value = "value"; var reader = new ExtendedAttributeReaderUnix(); Assert.That(reader.ListAttributeKeys(path).Count == 0); reader.SetExtendedAttribute(path, key, value); Assert.That(reader.ListAttributeKeys(path).Count == 1); Assert.Contains("test", reader.ListAttributeKeys(path)); }
public void RemoveAttributeFromFolder() { Directory.CreateDirectory(path); string key = "test"; string value = "value"; var reader = new ExtendedAttributeReaderUnix(); reader.SetExtendedAttribute(path, key, value); Assert.That(reader.GetExtendedAttribute(path, key).Equals(value)); reader.RemoveExtendedAttribute(path, key); Assert.That(reader.GetExtendedAttribute(path, key), Is.Null); }
public void OverwriteAttributeOnFolder() { Directory.CreateDirectory(path); string key = "test"; string value = "value"; string value2 = "value2"; var reader = new ExtendedAttributeReaderUnix(); reader.SetExtendedAttribute(path, key, value); reader.SetExtendedAttribute(path, key, value2); Assert.That(reader.GetExtendedAttribute(path, key).Equals(value2)); }
public void GetNullAttributeFromNewFolder() { Directory.CreateDirectory(path); string key = "test"; var reader = new ExtendedAttributeReaderUnix(); Assert.That(reader.GetExtendedAttribute(path, key), Is.Null); }
private void EnsureExtendedAttributesAreAvailable() { var reader = new ExtendedAttributeReaderUnix(); if (!reader.IsFeatureAvailable(this.testFolder)) { Assert.Ignore("Extended Attribute not available on this machine"); } }
public void RemoveNonExistingAttributeFromFile() { using (File.Create(path)); string key = "test"; var reader = new ExtendedAttributeReaderUnix(); reader.RemoveExtendedAttribute(path, key); Assert.That(reader.GetExtendedAttribute(path, key), Is.Null); }
/// <summary> /// Replaces the contents of a specified destinationFile with the file described by the current IFileInfo /// object, deleting the original file, and creating a backup of the replaced file. /// Also specifies whether to ignore merge errors. /// </summary> /// <param name="destinationFile">Destination file.</param> /// <param name="destinationBackupFileName">Destination backup file name.</param> /// <param name="ignoreMetadataErrors"><c>true</c> to ignore merge errors (such as attributes and ACLs) from the replaced file to the replacement file; otherwise <c>false</c>.</param> /// <returns>A IFileInfo object that encapsulates information about the file described by the destFileName parameter.</returns> public IFileInfo Replace(IFileInfo destinationFile, IFileInfo destinationBackupFileName, bool ignoreMetadataErrors) { #if __MonoCS__ var reader = new ExtendedAttributeReaderUnix(); var oldSourceEAs = new Dictionary<string, string>(); var oldTargetEAs = new Dictionary<string, string>(); if (reader.IsFeatureAvailable(this.FullName)) { foreach (var key in reader.ListAttributeKeys(this.FullName)) { oldSourceEAs.Add(key, this.GetExtendedAttribute(key)); } foreach (var key in reader.ListAttributeKeys(destinationFile.FullName)) { oldTargetEAs.Add(key, destinationFile.GetExtendedAttribute(key)); } } #else try { #endif var result = new FileInfoWrapper(this.original.Replace(destinationFile.FullName, destinationBackupFileName.FullName, ignoreMetadataErrors)); #if __MonoCS__ foreach (var entry in oldSourceEAs) { result.SetExtendedAttribute(entry.Key, entry.Value, true); } foreach (var entry in oldTargetEAs) { destinationBackupFileName.SetExtendedAttribute(entry.Key, entry.Value, true); } return result; #else return result; } catch (IOException ex) { int error = Marshal.GetHRForException(ex) & 0xffff; if (error == 1176) { string newName = destinationFile.FullName + Guid.NewGuid().ToString() + ".sync"; IFileInfo newResult = null; try { var copy = this.original.CopyTo(newName, true); newResult = new FileInfoWrapper(copy.Replace(destinationFile.FullName, destinationBackupFileName.FullName, ignoreMetadataErrors)); this.Delete(); return newResult; } catch (Exception) { } finally { if (File.Exists(newName)) { File.Delete(newName); } } throw; } else { throw; } } #endif }
/// <summary> /// Replaces the contents of a specified destinationFile with the file described by the current IFileInfo /// object, deleting the original file, and creating a backup of the replaced file. /// Also specifies whether to ignore merge errors. /// </summary> /// <param name="destinationFile">Destination file.</param> /// <param name="destinationBackupFileName">Destination backup file name.</param> /// <param name="ignoreMetadataErrors"><c>true</c> to ignore merge errors (such as attributes and ACLs) from the replaced file to the replacement file; otherwise <c>false</c>.</param> /// <returns>A IFileInfo object that encapsulates information about the file described by the destFileName parameter.</returns> public IFileInfo Replace(IFileInfo destinationFile, IFileInfo destinationBackupFileName, bool ignoreMetadataErrors) { #if __MonoCS__ var reader = new ExtendedAttributeReaderUnix(); var oldSourceEAs = new Dictionary <string, string>(); var oldTargetEAs = new Dictionary <string, string>(); if (reader.IsFeatureAvailable(this.FullName)) { foreach (var key in reader.ListAttributeKeys(this.FullName)) { oldSourceEAs.Add(key, this.GetExtendedAttribute(key)); } foreach (var key in reader.ListAttributeKeys(destinationFile.FullName)) { oldTargetEAs.Add(key, destinationFile.GetExtendedAttribute(key)); } } #else try { #endif var result = new FileInfoWrapper(this.original.Replace(destinationFile.FullName, destinationBackupFileName.FullName, ignoreMetadataErrors)); #if __MonoCS__ foreach (var entry in oldSourceEAs) { result.SetExtendedAttribute(entry.Key, entry.Value, true); } foreach (var entry in oldTargetEAs) { destinationBackupFileName.SetExtendedAttribute(entry.Key, entry.Value, true); } return(result); #else return(result); } catch (IOException ex) { int error = Marshal.GetHRForException(ex) & 0xffff; if (error == 1176) { string newName = destinationFile.FullName + Guid.NewGuid().ToString() + ".sync"; IFileInfo newResult = null; try { var copy = this.original.CopyTo(newName, true); newResult = new FileInfoWrapper(copy.Replace(destinationFile.FullName, destinationBackupFileName.FullName, ignoreMetadataErrors)); this.Delete(); return(newResult); } catch (Exception) { } finally { if (File.Exists(newName)) { File.Delete(newName); } } throw; } else { throw; } } #endif }