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
}
Esempio n. 2
0
File: main.go Progetto: ipfs/refs
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
}
Esempio n. 3
0
File: dmca.go Progetto: ipfs/refs
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
}