setAttributes sets permission, modification time and user/group ids on targetPath. modclear will clear the specified FileMod bits. Pass 0 to not clear any.
(targetPath string, e fs.Entry, modclear os.FileMode)
| 271 | // on targetPath. modclear will clear the specified FileMod bits. Pass 0 |
| 272 | // to not clear any. |
| 273 | func (o *FilesystemOutput) setAttributes(targetPath string, e fs.Entry, modclear os.FileMode) error { |
| 274 | le, err := localfs.NewEntry(targetPath) |
| 275 | if err != nil { |
| 276 | return errors.Wrap(err, "could not create local FS entry for "+targetPath) |
| 277 | } |
| 278 | |
| 279 | var ( |
| 280 | osChmod = os.Chmod |
| 281 | osChown = os.Chown |
| 282 | osChtimes = os.Chtimes |
| 283 | ) |
| 284 | |
| 285 | // symbolic links require special handling that is OS-specific and sometimes unsupported |
| 286 | // os.* functions change the target of the symlink and not the symlink itself. |
| 287 | if isSymlink(e) { |
| 288 | osChmod, osChown, osChtimes = symlinkChmod, symlinkChown, symlinkChtimes |
| 289 | modclear = os.FileMode(0) |
| 290 | } |
| 291 | |
| 292 | // Set owner user and group from e |
| 293 | // On Windows Chown is not supported. fs.OwnerInfo collected on Windows will always |
| 294 | // be zero-value for UID and GID, so the Chown operation is not performed. |
| 295 | if o.shouldUpdateOwner(le, e) { |
| 296 | if err = o.maybeIgnorePermissionError(osChown(targetPath, int(e.Owner().UserID), int(e.Owner().GroupID))); err != nil { |
| 297 | return errors.Wrap(err, "could not change owner/group for "+targetPath) |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | // Set file permissions from e |
| 302 | if o.shouldUpdatePermissions(le, e, modclear) { |
| 303 | if err = o.maybeIgnorePermissionError(osChmod(targetPath, (e.Mode()&fs.ModBits)&^modclear)); err != nil { |
| 304 | return errors.Wrap(err, "could not change permissions on "+targetPath) |
| 305 | } |
| 306 | } |
| 307 | |
| 308 | if o.shouldUpdateTimes(le, e) { |
| 309 | if err = o.maybeIgnorePermissionError(osChtimes(targetPath, e.ModTime(), e.ModTime())); err != nil { |
| 310 | return errors.Wrap(err, "could not change mod time on "+targetPath) |
| 311 | } |
| 312 | } |
| 313 | |
| 314 | return nil |
| 315 | } |
| 316 | |
| 317 | func isSymlink(e fs.Entry) bool { |
| 318 | _, ok := e.(fs.Symlink) |
no test coverage detected