예제 #1
0
func TestNewGenericFile(t *testing.T) {
	gf := models.NewGenericFile()
	assert.NotNil(t, gf.Checksums)
	assert.NotNil(t, gf.PremisEvents)
	assert.False(t, gf.IngestPreviousVersionExists)
	assert.True(t, gf.IngestNeedsSave)
}
예제 #2
0
파일: reader.go 프로젝트: APTrust/exchange
// Saves the file to disk and returns a GenericFile object.
func (reader *Reader) createAndSaveGenericFile(fileName string, header *tar.Header) *models.GenericFile {
	fileDir := filepath.Dir(reader.Manifest.Object.IngestUntarredPath)
	gf := models.NewGenericFile()
	reader.Manifest.Object.GenericFiles = append(reader.Manifest.Object.GenericFiles, gf)
	var err error
	gf.IngestLocalPath, err = filepath.Abs(filepath.Join(fileDir, header.Name))
	if err != nil {
		gf.IngestErrorMessage = fmt.Sprintf("Path error: %v", err)
		reader.Manifest.UntarResult.AddError(gf.IngestErrorMessage)
		return gf
	}
	gf.IntellectualObjectIdentifier = reader.Manifest.Object.Identifier
	gf.Identifier = fmt.Sprintf("%s/%s", reader.Manifest.Object.Identifier, gf.IngestLocalPath)
	gf.FileModified = header.ModTime
	gf.Size = header.Size
	gf.IngestFileUid = header.Uid
	gf.IngestFileGid = header.Gid
	gf.IngestFileUname = header.Uname
	gf.IngestFileGname = header.Gname
	gf.IngestUUID = uuid.NewV4().String()
	gf.IngestUUIDGeneratedAt = time.Now().UTC()
	reader.saveWithChecksums(gf)
	return gf
}