diff --git a/repo.go b/repo.go index cc1a3167..37fec3e9 100644 --- a/repo.go +++ b/repo.go @@ -647,6 +647,25 @@ func (r *Repo) RemoveTargetsWithExpires(paths []string, expires time.Time) error return r.setMeta("targets.json", t) } +func (r *Repo) Root() error { + return r.RootWithExpires(data.DefaultExpires("root")) +} + +func (r *Repo) RootWithExpires(expires time.Time) error { + if !validExpires(expires) { + return ErrInvalidExpires{expires} + } + + root, err := r.root() + if err != nil { + return err + } + + root.Expires = expires + + return r.setMeta("root.json", root) +} + func (r *Repo) Snapshot(t CompressionType) error { return r.SnapshotWithExpires(t, data.DefaultExpires("snapshot")) } diff --git a/util/util.go b/util/util.go index 751c677e..e7d6ed27 100644 --- a/util/util.go +++ b/util/util.go @@ -280,7 +280,7 @@ func AtomicallyWriteFile(filename string, data []byte, perm os.FileMode) error { return err } - if err = f.Chmod(perm); err != nil { + if err = os.Chmod(f.Name(), perm); err != nil { f.Close() os.Remove(f.Name()) return err