func tryPin(s sayer, path string, sh *shell.Shell) error { out, err := sh.Refs(path, true) if err != nil { return fmt.Errorf("failed to grab refs for %s: %s", path, err) } // throw away results for _ = range out { } err = sh.Pin(path) if err != nil { return fmt.Errorf("failed to pin %s: %s", path, err) } return nil }
func addPrevious(hist string, lhash string, sh *shell.Shell) (string, error) { b, err := ioutil.ReadFile(hist) if err != nil { return "", err } var vhash string s := bufio.NewScanner(strings.NewReader(string(b))) for s.Scan() { vhash = s.Text() } nhash, err := sh.PatchLink(lhash, "previous", vhash, true) if err != nil { return "", err } return nhash, nil }
func addPrevious(sh *shell.Shell, h string, c string) (string, error) { cur, err := sh.ResolvePath(c) if err != nil { log.Fatalf("could not resolve current version: %s", err) } prev, err := sh.ResolvePath(c + "/previous") if err == nil { h, err = sh.PatchLink(h, "previous", prev, true) if err != nil { return "", err } } if h != cur { h, err = sh.PatchLink(h, "previous", cur, true) if err != nil { return "", err } } return h, nil }
func addDenylist(srcpath string, sh *shell.Shell) (string, error) { dirs, err := AssetDir(srcpath) if err != nil { return "", err } h, err := sh.NewObject("unixfs-dir") if err != nil { return "", err } for _, dirname := range dirs { keys, nreader, err := keysAndNotice(srcpath + "/" + dirname) if err != nil { return "", err } n, err := sh.Add(nreader) if err != nil { return "", err } for i, k := range keys { n, err = sh.PatchLink(n, fmt.Sprintf("object-%d", i), k, true) if err != nil { return "", err } } h, err = sh.PatchLink(h, dirname, n, true) if err != nil { return "", err } } return h, nil }
func addSkeleton(sh *shell.Shell, dmca string) (string, error) { hdenylists, err := sh.NewObject("unixfs-dir") if err != nil { return "", err } hdenylists, err = sh.PatchLink(hdenylists, "dmca", dmca, true) if err != nil { return "", err } hlists, err := sh.NewObject("unixfs-dir") if err != nil { return "", err } hlists, err = sh.PatchLink(hlists, "denylists", hdenylists, true) if err != nil { return "", err } hroot, err := sh.NewObject("unixfs-dir") if err != nil { return "", err } hroot, err = sh.PatchLink(hroot, "lists", hlists, true) if err != nil { return "", err } return hroot, nil }
func addDenylist(srcpath string, sh *shell.Shell) (string, error) { srcdir, err := os.Open(srcpath) if err != nil { return "", err } ndirs, err := srcdir.Readdir(0) if err != nil { return "", err } lhash, err := sh.NewObject("unixfs-dir") if err != nil { return "", err } for _, dir := range ndirs { omit := regexp.MustCompile(`\A(\.|node_modules|versions)`) if !dir.IsDir() || omit.Match([]byte(dir.Name())) { continue } keys, nreader, err := keysAndNotice(srcdir.Name() + "/" + dir.Name()) if err != nil { return "", err } nhash, err := sh.Add(nreader) if err != nil { return "", err } for _, k := range keys { dhash, err := sh.NewObject("unixfs-dir") if err != nil { return "", err } dhash, err = sh.PatchLink(dhash, "notice", nhash, true) if err != nil { return "", err } dhash, err = sh.PatchLink(dhash, "object", k, true) if err != nil { return "", err } link := fmt.Sprintf("%s-%s", dir.Name(), k) lhash, err = sh.PatchLink(lhash, link, dhash, true) if err != nil { return "", err } } } return lhash, nil }