コード例 #1
0
ファイル: load.go プロジェクト: keep94/Dominator
func loadImageDataBase(baseDir string, objSrv objectserver.FullObjectServer,
	cleanupUnreferencedObjects bool,
	logger *log.Logger) (*ImageDataBase, error) {
	fi, err := os.Stat(baseDir)
	if err != nil {
		return nil, errors.New(
			fmt.Sprintf("Cannot stat: %s: %s\n", baseDir, err))
	}
	if !fi.IsDir() {
		return nil, errors.New(fmt.Sprintf("%s is not a directory\n", baseDir))
	}
	imdb := &ImageDataBase{
		baseDir:                    baseDir,
		directoryMap:               make(map[string]image.DirectoryMetadata),
		imageMap:                   make(map[string]*image.Image),
		addNotifiers:               make(notifiers),
		deleteNotifiers:            make(notifiers),
		mkdirNotifiers:             make(makeDirectoryNotifiers),
		objectServer:               objSrv,
		cleanupUnreferencedObjects: cleanupUnreferencedObjects,
		logger: logger,
	}
	state := concurrent.NewState(0)
	startTime := time.Now()
	var rusageStart, rusageStop syscall.Rusage
	syscall.Getrusage(syscall.RUSAGE_SELF, &rusageStart)
	if err := imdb.scanDirectory(".", state, logger); err != nil {
		return nil, err
	}
	if err := state.Reap(); err != nil {
		return nil, err
	}
	if logger != nil {
		plural := ""
		if imdb.CountImages() != 1 {
			plural = "s"
		}
		syscall.Getrusage(syscall.RUSAGE_SELF, &rusageStop)
		userTime := time.Duration(rusageStop.Utime.Sec)*time.Second +
			time.Duration(rusageStop.Utime.Usec)*time.Microsecond -
			time.Duration(rusageStart.Utime.Sec)*time.Second -
			time.Duration(rusageStart.Utime.Usec)*time.Microsecond
		logger.Printf("Loaded %d image%s in %s (%s user CPUtime)\n",
			imdb.CountImages(), plural, time.Since(startTime), userTime)
	}
	return imdb, nil
}
コード例 #2
0
ファイル: walk.go プロジェクト: keep94/Dominator
func walk(rootDirName, dirName, objectsDir string) error {
	var state stateType
	state.processedInodes = make(map[uint64]struct{})
	state.directoriesToRemove = make([]string, 0)
	state.concurrencyState = concurrent.NewState(0)
	if err := state.walk(rootDirName, dirName, objectsDir); err != nil {
		return err
	}
	if err := state.concurrencyState.Reap(); err != nil {
		return err
	}
	for _, dirname := range state.directoriesToRemove {
		if err := os.Remove(dirname); err != nil {
			return err
		}
	}
	return nil
}