Esempio n. 1
0
File: lock.go Progetto: rht/ipget
func Locked(confdir string) (bool, error) {
	if !util.FileExists(path.Join(confdir, LockFile)) {
		return false, nil
	}
	if lk, err := Lock(confdir); err != nil {
		// EAGAIN == someone else has the lock
		if err == syscall.EAGAIN {
			return true, nil
		}
		if strings.Contains(err.Error(), "can't Lock file") {
			return true, nil
		}

		// lock fails on permissions error
		if os.IsPermission(err) {
			return false, errPerm(confdir)
		}
		if isLockCreatePermFail(err) {
			return false, errPerm(confdir)
		}

		// otherwise, we cant guarantee anything, error out
		return false, err
	} else {
		lk.Close()
		return false, nil
	}
}
Esempio n. 2
0
File: fsrepo.go Progetto: rht/ipget
// isInitializedUnsynced reports whether the repo is initialized. Caller must
// hold the packageLock.
func isInitializedUnsynced(repoPath string) bool {
	if !configIsInitialized(repoPath) {
		return false
	}
	if !util.FileExists(path.Join(repoPath, leveldbDirectory)) {
		return false
	}
	return true
}
Esempio n. 3
0
File: fsrepo.go Progetto: rht/ipget
// configIsInitialized returns true if the repo is initialized at
// provided |path|.
func configIsInitialized(path string) bool {
	configFilename, err := config.Filename(path)
	if err != nil {
		return false
	}
	if !util.FileExists(configFilename) {
		return false
	}
	return true
}
Esempio n. 4
0
// Load reads given file and returns the read config, or error.
func Load(filename string) (*config.Config, error) {
	// if nothing is there, fail. User must run 'ipfs init'
	if !util.FileExists(filename) {
		return nil, errors.New("ipfs not initialized, please run 'ipfs init'")
	}

	var cfg config.Config
	err := ReadConfigFile(filename, &cfg)
	if err != nil {
		return nil, err
	}

	// tilde expansion on datastore path
	// TODO why is this here??
	cfg.Datastore.Path, err = util.TildeExpansion(cfg.Datastore.Path)
	if err != nil {
		return nil, err
	}

	return &cfg, err
}