コード例 #1
0
ファイル: col.go プロジェクト: jbenet/tiedot
// Open a hash table index and put it into collection structure.
func (col *Col) openIndex(indexPath []string, baseDir string) {
	jointPath := strings.Join(indexPath, INDEX_PATH_SEP)
	tables := make([]*chunkfile.HashTable, col.NumChunks)
	for i := 0; i < col.NumChunks; i++ {
		if err := os.MkdirAll(baseDir, 0700); err != nil {
			panic(err)
		}
		table, err := chunkfile.OpenHash(path.Join(baseDir, strconv.Itoa(int(i))), indexPath)
		if err != nil {
			panic(err)
		}
		tables[i] = table
	}
	col.SecIndexes[jointPath] = tables
}
コード例 #2
0
ファイル: chunkcol.go プロジェクト: jbenet/tiedot
// Open a chunk.
func OpenChunk(number int, baseDir string) (chunk *ChunkCol, err error) {
	// Create the directory if it does not yet exist
	if err = os.MkdirAll(baseDir, 0700); err != nil {
		return
	}
	tdlog.Printf("Opening chunk %s", baseDir)
	chunk = &ChunkCol{Number: number, BaseDir: baseDir}
	// Open collection document data file
	tdlog.Printf("Opening collection data file %s", DAT_FILENAME_MAGIC)
	if chunk.Data, err = chunkfile.OpenCol(path.Join(baseDir, DAT_FILENAME_MAGIC)); err != nil {
		return
	}
	// Open PK hash table
	tdlog.Printf("Opening PK hash table file %s", PK_FILENAME_MAGIC)
	if chunk.PK, err = chunkfile.OpenHash(path.Join(baseDir, PK_FILENAME_MAGIC), []string{uid.PK_NAME}); err != nil {
		return
	}
	return
}