当前位置: 首页>>代码示例>>Golang>>正文


Golang GenericFile.Id方法代码示例

本文整理汇总了Golang中github.com/APTrust/exchange/models.GenericFile.Id方法的典型用法代码示例。如果您正苦于以下问题:Golang GenericFile.Id方法的具体用法?Golang GenericFile.Id怎么用?Golang GenericFile.Id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/APTrust/exchange/models.GenericFile的用法示例。


在下文中一共展示了GenericFile.Id方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: saveFile

func (storer *APTStorer) saveFile(ingestState *models.IngestState, gf *models.GenericFile) {
	existingSha256, err := storer.getExistingSha256(gf.Identifier)
	if err != nil {
		storer.Context.MessageLog.Error(err.Error())
		ingestState.IngestManifest.StoreResult.AddError(err.Error())
		return
	}
	// Set this, for the record.
	if existingSha256 != nil {
		gf.IngestPreviousVersionExists = true
		gf.Id = existingSha256.GenericFileId

		uuid, err := storer.getUuidOfExistingFile(gf.Identifier)
		if err != nil {
			message := fmt.Sprintf("Cannot find existing UUID for %s: %v", gf.Identifier, err.Error())
			ingestState.IngestManifest.StoreResult.AddError(message)
			storer.Context.MessageLog.Error(message)
			// Probably not fatal, but treat it as such for now,
			// because we don't want leave orphan objects in S3,
			// or have the GenericFile.URL not match the actual
			// storage URL. This should only happen if a depositor
			// deletes the existing version of a GenericFile while
			// we are processing this ingest. The window for that
			// to happen is usually between a few seconds and a few
			// hours.
			ingestState.IngestManifest.StoreResult.ErrorIsFatal = true
			return
		}
		if uuid == "" {
			message := fmt.Sprintf("Cannot find existing UUID for %s.", gf.Identifier)
			ingestState.IngestManifest.StoreResult.AddError(message)
			storer.Context.MessageLog.Error(message)
			// Probably not fatal, but treat it as such for now.
			// Same note as in previous if statement above.
			ingestState.IngestManifest.StoreResult.ErrorIsFatal = true
			return
		} else {
			// OK. Set the GenericFile's UUID to match the existing file's
			// UUID, so that we overwrite the existing file, and so the
			// GenericFile record in Pharos still has the correct URL.
			message := fmt.Sprintf("Resetting UUID for '%s' to '%s' so we can overwrite "+
				"the currently stored version of the file.",
				gf.Identifier, uuid)
			storer.Context.MessageLog.Info(message)
			// TODO: Test this in integration post test.
			gf.IngestUUID = uuid
		}

		if existingSha256.Digest != gf.IngestSha256 {
			storer.Context.MessageLog.Info(
				"GenericFile %s has same sha256. Does not need save.", gf.Identifier)
			gf.IngestNeedsSave = false
		}
	}
	// Now copy to storage only if the file has changed.
	if gf.IngestNeedsSave {
		storer.Context.MessageLog.Info("File %s needs save", gf.Identifier)
		if gf.IngestStoredAt.IsZero() || gf.IngestStorageURL == "" {
			storer.copyToLongTermStorage(ingestState, gf, "s3")
		}
		if gf.IngestReplicatedAt.IsZero() || gf.IngestReplicationURL == "" {
			storer.copyToLongTermStorage(ingestState, gf, "glacier")
		}
	}
}
开发者ID:APTrust,项目名称:exchange,代码行数:65,代码来源:apt_storer.go


注:本文中的github.com/APTrust/exchange/models.GenericFile.Id方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。