Example #1
0
func (gen uuidV4Generator) Generate() (uuidStr string, err error) {
	uuid, err := gouuid.NewV4()
	if err != nil {
		err = bosherr.WrapError(err, "Generating V4 uuid")
		return
	}

	uuidStr = uuid.String()
	return
}
Example #2
0
func (fs *FakeFileSystem) TempDir(prefix string) (string, error) {
	fs.filesLock.Lock()
	defer fs.filesLock.Unlock()

	if fs.TempDirError != nil {
		return "", fs.TempDirError
	}

	if fs.strictTempRoot && fs.TempRootPath == "" {
		return "", errors.New("Temp file was requested without having set a temp root")
	}

	var path string
	if len(fs.TempDirDir) > 0 {
		path = fs.TempDirDir
	} else if fs.TempDirDirs != nil {
		if len(fs.TempDirDirs) == 0 {
			return "", errors.New("Failed to create new temp dir: TempDirDirs is empty")
		}
		path = fs.TempDirDirs[0]
		fs.TempDirDirs = fs.TempDirDirs[1:]
	} else {
		uuid, err := gouuid.NewV4()
		if err != nil {
			return "", err
		}

		path = uuid.String()
	}

	// Make sure to record a reference for FileExist, etc. to work
	stats := fs.getOrCreateFile(path)
	stats.FileType = FakeFileTypeDir

	return path, nil
}