util

package
v2.1.2+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 13, 2019 License: Apache-2.0 Imports: 8 Imported by: 11

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BagNameFromTarFileName

func BagNameFromTarFileName(pathToTarFile string) string

BagNameFromTarFileName returns the bag name of the specified tar file. This works even for tar files with names like 'test.edu.my_bag.b01.of12.tar'. That will return 'test.edu.my_bag'.

func Base64EncodeMd5

func Base64EncodeMd5(md5Digest string) (string, error)

Base64EncodeMd5 returns a base64-encoded md5 digest. The is the format S3 wants.

func BucketNameAndKey

func BucketNameAndKey(uri string) (string, string)

BucketNameAndKey returns the bucket name and key of the specified url, which is expected to be an S3 URI.

func CleanBagName

func CleanBagName(bagName string) string

CleanBagName returns the clean bag name. That's the tar file name minus the tar extension and any ".bagN.ofN" suffix.

func CleanString

func CleanString(str string) string

CleanString cleans a string we might find a config file, trimming leading and trailing spaces, single quotes and double quoted. Note that leading and trailing spaces inside the quotes are not trimmed.

func ContainsControlCharacter

func ContainsControlCharacter(str string) bool

ContainsControlCharacter returns true if string str contains a Unicode control character. We use this to test file names, which should not contain control characters.

func DeleteFromStringList

func DeleteFromStringList(list []string, item string) []string

DeleteFromStringList deletes item from list and returns a new slice.

func GetInstitutionFromBagName

func GetInstitutionFromBagName(bagName string) (string, error)

GetInstitutionFromBagName returns the instution name from the bag name, or an error if the bag name does not contain the institution name. For example, "virginia.edu.bag_of_videos.tar" returns "virginia.edu" and no errors. "virginia.edu.bag_of_videos" returns the same thing. But "bag_of_videos.tar" or "virginia.bag_of_videos.tar" returns an error because the institution identifier is missing from the bag name.

func HasSavableName

func HasSavableName(filename string) bool

HasSavableNamereturns true if the file name indicates this is something we should save to long-term storage. As of late March, 2016, we save everything in the bag except bagit.txt, manifest-<algo>.txt and tagmanifest-<algo>.txt. Those files we don't save will be reconstructed when the bag is restored.

Param filename should be the relative path of the file within the bag. For example, "tagmanifest-sha256.txt" or "data/images/photo_01.jpg". This is important, because a file called "manifest-md5.txt" will return false (indicating it should not be saved), while a file called "data/manifest-md5.txt" will return true, because its file path indicates it's part of the payload.

We reconstruct bagit.txt because we may have moved to a newer version by the time the file is restored. We reconstruct manifests and tag manifests because payload files and tag files may be deleted or overwritten by the depositor between initial ingest and restoration.

And did you know both savable and saveable are correct? I chose the former to reduce the size of our compiled binary by one byte. That could save us pennies over the next 10,000 years.

func IntListContains

func IntListContains(list []int, item int) bool

IntListContains returns true if the list of ints contains item.

func IsGlacierDeepArchive

func IsGlacierDeepArchive(storageOption string) bool

IsGlacierDeepArchive returns true if bucketName matches any of our Glacier Deep Archive storage buckets.

func LooksLikeEscapedControl

func LooksLikeEscapedControl(str string) bool

LooksLikeEscapedControl returns true if string str contains something that looks like an escaped UTF-8 control character. The Mac OS file system seems to silently escape UTF-8 control characters. That causes problems when we try to copy a file over to another file system that won't accept the control character in a file name. The bag validator looks for file names matching these patterns and rejects them.

func LooksLikeJunkFile

func LooksLikeJunkFile(filename string) bool

LooksLikeJunkFile returns true if the filename looks like a MacOS junk file. These are dot-underscore files that contain extended file attributes. These files are often unintentionally included in tarred bags created on MacOS. They may not appear in the manifests, and that will cause bag validation to fail. Part of https://www.pivotaltracker.com/story/show/151265762

func LooksLikeURL

func LooksLikeURL(url string) bool

LooksLikeURL returns true if url looks like a URL.

func LooksLikeUUID

func LooksLikeUUID(uuid string) bool

LooksLikeUUID returns true if uuid looks like a valid UUID.

func Min

func Min(x, y int) int

Min returns the minimum of x or y. The Math package has this function but you have to cast to floats.

func OwnerOf

func OwnerOf(bucketName string) (institution string)

OwnerOf returns the domain name of the institution that owns the specified bucket. For example, if bucketName is 'aptrust.receiving.unc.edu' the return value will be 'unc.edu'.

func PointerToString

func PointerToString(strPointer *string) string

PointerToString returns the string pointed to, or an empty string if the pointer is nil.

func RestorationBucketFor

func RestorationBucketFor(institution string, restoreToTestBuckets bool) (bucketName string)

RestorationBucketFor returns the name of the specified institution's restoration bucket. E.g. institution 'unc.edu' returns bucketName 'aptrust.restore.unc.edu'. The second param, restoreToTestBuckets, is set the in the config json file and accessible through Config.RestoreToTestBuckets. It should be true everywhere except in the production environment. If true, this will return 'aptrust.restore.test.unc.edu'.

func StringListContains

func StringListContains(list []string, item string) bool

StringListContains returns true if the list of strings contains item.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL