// last ditch effort to ensure temp file is removed /// <summary>Preserve the attributes of the source to the target.</summary> /// <remarks> /// Preserve the attributes of the source to the target. /// The method calls /// <see cref="ShouldPreserve(FileAttribute)"/> /// to check what /// attribute to preserve. /// </remarks> /// <param name="src">source to preserve</param> /// <param name="target">where to preserve attributes</param> /// <param name="preserveRawXAttrs">true if raw.* xattrs should be preserved</param> /// <exception cref="System.IO.IOException">if fails to preserve attributes</exception> protected internal virtual void PreserveAttributes(PathData src, PathData target, bool preserveRawXAttrs) { if (ShouldPreserve(CommandWithDestination.FileAttribute.Timestamps)) { target.fs.SetTimes(target.path, src.stat.GetModificationTime(), src.stat.GetAccessTime ()); } if (ShouldPreserve(CommandWithDestination.FileAttribute.Ownership)) { target.fs.SetOwner(target.path, src.stat.GetOwner(), src.stat.GetGroup()); } if (ShouldPreserve(CommandWithDestination.FileAttribute.Permission) || ShouldPreserve (CommandWithDestination.FileAttribute.Acl)) { target.fs.SetPermission(target.path, src.stat.GetPermission()); } if (ShouldPreserve(CommandWithDestination.FileAttribute.Acl)) { FsPermission perm = src.stat.GetPermission(); if (perm.GetAclBit()) { IList <AclEntry> srcEntries = src.fs.GetAclStatus(src.path).GetEntries(); IList <AclEntry> srcFullEntries = AclUtil.GetAclFromPermAndEntries(perm, srcEntries ); target.fs.SetAcl(target.path, srcFullEntries); } } bool preserveXAttrs = ShouldPreserve(CommandWithDestination.FileAttribute.Xattr); if (preserveXAttrs || preserveRawXAttrs) { IDictionary <string, byte[]> srcXAttrs = src.fs.GetXAttrs(src.path); if (srcXAttrs != null) { IEnumerator <KeyValuePair <string, byte[]> > iter = srcXAttrs.GetEnumerator(); while (iter.HasNext()) { KeyValuePair <string, byte[]> entry = iter.Next(); string xattrName = entry.Key; if (xattrName.StartsWith(Raw) || preserveXAttrs) { target.fs.SetXAttr(target.path, entry.Key, entry.Value); } } } } }
/// <exception cref="System.IO.IOException"/> protected internal override void ProcessPath(PathData item) { @out.WriteLine("# file: " + item); @out.WriteLine("# owner: " + item.stat.GetOwner()); @out.WriteLine("# group: " + item.stat.GetGroup()); FsPermission perm = item.stat.GetPermission(); if (perm.GetStickyBit()) { @out.WriteLine("# flags: --" + (perm.GetOtherAction().Implies(FsAction.Execute) ? "t" : "T")); } AclStatus aclStatus = item.fs.GetAclStatus(item.path); IList <AclEntry> entries = perm.GetAclBit() ? aclStatus.GetEntries() : Collections .EmptyList <AclEntry>(); ScopedAclEntries scopedEntries = new ScopedAclEntries(AclUtil.GetAclFromPermAndEntries (perm, entries)); PrintAclEntriesForSingleScope(aclStatus, perm, scopedEntries.GetAccessEntries()); PrintAclEntriesForSingleScope(aclStatus, perm, scopedEntries.GetDefaultEntries()); @out.WriteLine(); }