Exemplo n.º 1
0
func TestIDofIDSlice(t *testing.T) {
	is := is.New(t)
	var b, s []byte
	for i := 0; i < 64; i++ {
		b = append(b, 0xFF)
		s = append(s, 0x00)
	}
	bigBig := big.NewInt(0)
	bigSmall := big.NewInt(0)
	bigBig = bigBig.SetBytes(b)
	bigSmall = bigSmall.SetBytes(s)
	bigID := asset.ID(*bigBig)
	smallID := asset.ID(*bigSmall)

	encoder := asset.NewIDEncoder()
	is.OK(encoder)
	_, err := io.Copy(encoder, strings.NewReader(`c41111111111111111111111111111111111111111111111111111111111111111111111111111111111111111c467RPWkcUr5dga8jgywjSup7CMoA9FNqkNjEFgAkEpF9vNktFnx77e2Js11EDL3BNu9MaKFUbacZRt1HYym4b8RNp`))
	is.NoErr(err)
	id := encoder.ID()

	var idSlice asset.IDSlice
	idSlice.Push(&bigID)
	idSlice.Push(&smallID)
	sliceID, err := idSlice.ID()
	is.NoErr(err)

	is.Equal(sliceID.String(), id.String())
}
Exemplo n.º 2
0
func walkFilesystem(depth int, filename string, relative_path string) (*asset.ID, error) {
	path, err := filepath.Abs(filename)
	if err != nil {
		return nil, err
	}

	item := &FsItem{}
	err = item.Stat(path)
	if err != nil {
		return nil, err
	}

	if item.IsFile() {
		id, err := item.Identify()
		if err != nil {
			return nil, err
		}
		item.Id = id
	} else if item.Link {
		newFilepath, err := filepath.EvalSymlinks(filename)
		if err != nil {
			return nil, err
		}
		item.LinkPath = &newFilepath
		if links_flag { // Then follow the link
			id, err := walkFilesystem(depth, newFilepath, relative_path)
			if err != nil {
				return item.Id, err
			}
			item.Id = id
		}
	} else if item.Folder {
		files, err := ioutil.ReadDir(path)
		if err != nil {
			return item.Id, err
		}
		var childIDs asset.IDSlice
		for _, file := range files {
			path := filename + string(filepath.Separator) + file.Name()
			id, err := walkFilesystem(depth-1, path, relative_path)
			if err != nil {
				return item.Id, err
			}
			childIDs.Push(id)
		}
		id, err := childIDs.ID()
		if err != nil {
			return item.Id, err
		}
		item.Id = id
	}
	if depth >= 0 || recursive_flag {
		output(item)
	}
	return item.Id, nil
}