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
}
}