Skip to content

Commit

Permalink
feat(timestamps): add to dir and file meta (#24)
Browse files Browse the repository at this point in the history
The mapping is not exact and is to the best possible match.

- For the mounted root dir, it uses the GitHub repo updated time
- For release dirs, it uses the GitHub release published time
- For release asset files, it uses asset updated time

Bump version to 0.1.3 for release.
  • Loading branch information
guangie88 authored May 20, 2020
1 parent 635515a commit 8a19c41
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
31 changes: 30 additions & 1 deletion ghafs.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,17 @@ func (g ghaFS) Root() (fs.Node, error) {
return root{mgmt: g.mgmt, token: g.token}, nil
}

func (root) Attr(ctx context.Context, a *fuse.Attr) error {
func (r root) Attr(ctx context.Context, a *fuse.Attr) error {
a.Inode = 1
a.Mode = os.ModeDir | 0775

cmaTime := r.mgmt.repo.GetUpdatedAt().Time
a.Ctime = cmaTime
a.Mtime = cmaTime
a.Atime = cmaTime

a.Crtime = r.mgmt.repo.GetCreatedAt().Time

return nil
}

Expand Down Expand Up @@ -80,6 +88,15 @@ func (r root) Lookup(ctx context.Context, name string) (fs.Node, error) {
func (t tagDir) Attr(ctx context.Context, a *fuse.Attr) error {
a.Inode = uint64(t.assets.release.GetID())
a.Mode = os.ModeDir | 0775

// GitHub release only keeps track of Created (tag creation) and Published (release published) timestamps
// Since we are not interested in the tag, and only in the release, we use the published timestamp
cmaTime := t.assets.release.GetPublishedAt().Time
a.Ctime = cmaTime
a.Mtime = cmaTime
a.Atime = cmaTime
a.Crtime = cmaTime

return nil
}

Expand Down Expand Up @@ -112,6 +129,18 @@ func (f assetFile) Attr(ctx context.Context, a *fuse.Attr) error {
a.Inode = uint64(f.asset.GetID())
a.Mode = 0664
a.Size = uint64(f.asset.GetSize())

// Ctime -> file meta change time, e.g. change owner, change perms
// Mtime -> file content modification time
// Atime -> file access time, since GitHub does not track this, we just use the updated time
cmaTime := f.asset.GetUpdatedAt().Time
a.Ctime = cmaTime
a.Mtime = cmaTime
a.Atime = cmaTime

// Crtime -> file created time
a.Crtime = f.asset.GetCreatedAt().Time

return nil
}

Expand Down
8 changes: 6 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (args) Description() string {
}

func (args) Version() string {
return "ghafs 0.1.2"
return "ghafs 0.1.3"
}

func main() {
Expand All @@ -48,7 +48,11 @@ func main() {
}

client := github.NewClient(tc)
mgmt := makeReleaseMgmt(makeGhContext(ctx, client, args.Owner, args.Repo, time.Duration(args.RefreshThreshold)*time.Second))
mgmt, err := makeReleaseMgmt(makeGhContext(ctx, client, args.Owner, args.Repo, time.Duration(args.RefreshThreshold)*time.Second))

if err != nil {
log.Fatal(err)
}

mountOptions := []fuse.MountOption{
fuse.FSName("ghafs"),
Expand Down
11 changes: 9 additions & 2 deletions releaseAssets.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type GhContext struct {
// assets content with the given GitHub context
type ReleaseMgmt struct {
ghc *GhContext
repo *github.Repository
releases *ReleasesWrap
}

Expand Down Expand Up @@ -60,8 +61,14 @@ func makeGhContext(ctx context.Context, client *github.Client, owner string, rep
return &GhContext{ctx, client, owner, repo, refreshThreshold}
}

func makeReleaseMgmt(ghc *GhContext) *ReleaseMgmt {
return &ReleaseMgmt{ghc, makeReleasesWrap(ghc)}
func makeReleaseMgmt(ghc *GhContext) (*ReleaseMgmt, error) {
repo, _, err := ghc.client.Repositories.Get(ghc.ctx, ghc.owner, ghc.repo)

if err != nil {
return nil, err
}

return &ReleaseMgmt{ghc, repo, makeReleasesWrap(ghc)}, nil
}

func makeReleasesWrap(ghc *GhContext) *ReleasesWrap {
Expand Down

0 comments on commit 8a19c41

Please sign in to comment.