newDirEntry makes DirEntry objects for any type of Entry.
(md fs.Entry, fname string, oid object.ID)
| 448 | |
| 449 | // newDirEntry makes DirEntry objects for any type of Entry. |
| 450 | func newDirEntry(md fs.Entry, fname string, oid object.ID) (*snapshot.DirEntry, error) { |
| 451 | var entryType snapshot.EntryType |
| 452 | |
| 453 | switch md := md.(type) { |
| 454 | case fs.Directory: |
| 455 | entryType = snapshot.EntryTypeDirectory |
| 456 | case fs.Symlink: |
| 457 | entryType = snapshot.EntryTypeSymlink |
| 458 | case fs.File, fs.StreamingFile: |
| 459 | entryType = snapshot.EntryTypeFile |
| 460 | default: |
| 461 | return nil, errors.Errorf("invalid entry type %T", md) |
| 462 | } |
| 463 | |
| 464 | return &snapshot.DirEntry{ |
| 465 | Name: fname, |
| 466 | Type: entryType, |
| 467 | Permissions: snapshot.Permissions(md.Mode() & fs.ModBits), |
| 468 | FileSize: md.Size(), |
| 469 | ModTime: fs.UTCTimestampFromTime(md.ModTime()), |
| 470 | UserID: md.Owner().UserID, |
| 471 | GroupID: md.Owner().GroupID, |
| 472 | ObjectID: oid, |
| 473 | }, nil |
| 474 | } |
| 475 | |
| 476 | // newCachedDirEntry makes DirEntry objects for entries that are also in |
| 477 | // previous snapshots. It ensures file sizes are populated correctly for |
no test coverage detected