Exemple #1
0
func (gs GlacierStorage) GetFilesList() ([]base.GenericStorageFileInfo, error) {
	var filesList []base.GenericStorageFileInfo
	activeJob, err := gs.findJob(glacier.ActionCodeInventoryRetrieval, "")
	if err != nil {
		return filesList, err
	}

	if activeJob == nil {
		params := &glacier.InitiateJobInput{
			AccountId: aws.String("-"),
			VaultName: aws.String(gs.vault_name),
			JobParameters: &glacier.JobParameters{
				Type: aws.String("inventory-retrieval"),
			},
		}
		result, err := gs.getStorageClient().InitiateJob(params)
		if err != nil {
			return filesList, err
		}
		activeJob, err = gs.getJob(result.JobId)
		if err != nil {
			return filesList, err
		}
	}

	activeJob, err = gs.waitJobComplete(activeJob, 0, 1)
	if err != nil {
		return filesList, err
	}

	params := &glacier.GetJobOutputInput{
		AccountId: aws.String("-"),
		VaultName: aws.String(gs.vault_name),
		JobId:     activeJob.JobId}
	result, err := gs.getStorageClient().GetJobOutput(params)
	if err != nil {
		return filesList, err
	}

	type jsonJobResp struct {
		ArchiveList []GlacierFileInfo
	}
	var jobResp jsonJobResp
	jsonResp, err := ioutil.ReadAll(result.Body)
	if err == nil {
		err = json.Unmarshal(jsonResp, &jobResp)
	}
	if err != nil {
		return filesList, err
	}
	for _, gfi := range jobResp.ArchiveList {
		filesList = append(filesList, base.GenericStorageFileInfo(gfi))
	}
	return filesList, nil
}
Exemple #2
0
func (ls LocalFSStorage) GetFilesList() ([]base.GenericStorageFileInfo, error) {
	var filesList []base.GenericStorageFileInfo

	dirNodes, err := ioutil.ReadDir(ls.path)
	if err != nil {
		return filesList, err
	}

	for _, fi := range dirNodes {
		if !fi.IsDir() {
			filesList = append(filesList, base.GenericStorageFileInfo(LocalFSFileInfo{filename: fi.Name()}))
		}
	}

	return filesList, nil
}