mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-07-16 12:08:04 +00:00
New upstream version 1.5.0+ds1
This commit is contained in:
+36
-4
@@ -49,6 +49,8 @@ func NewPublishedStorageRaw(
|
||||
) (*PublishedStorage, error) {
|
||||
if defaultACL == "" {
|
||||
defaultACL = "private"
|
||||
} else if defaultACL == "none" {
|
||||
defaultACL = ""
|
||||
}
|
||||
|
||||
if storageClass == "STANDARD" {
|
||||
@@ -142,7 +144,7 @@ func (storage *PublishedStorage) PutFile(path string, sourceFilename string) err
|
||||
}
|
||||
defer source.Close()
|
||||
|
||||
err = storage.putFile(path, source)
|
||||
err = storage.putFile(path, source, "")
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, fmt.Sprintf("error uploading %s to %s", sourceFilename, storage))
|
||||
}
|
||||
@@ -150,8 +152,22 @@ func (storage *PublishedStorage) PutFile(path string, sourceFilename string) err
|
||||
return err
|
||||
}
|
||||
|
||||
// getMD5 retrieves MD5 stored in the metadata, if any
|
||||
func (storage *PublishedStorage) getMD5(path string) (string, error) {
|
||||
params := &s3.HeadObjectInput{
|
||||
Bucket: aws.String(storage.bucket),
|
||||
Key: aws.String(filepath.Join(storage.prefix, path)),
|
||||
}
|
||||
output, err := storage.s3.HeadObject(params)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return aws.StringValue(output.Metadata["Md5"]), nil
|
||||
}
|
||||
|
||||
// putFile uploads file-like object to
|
||||
func (storage *PublishedStorage) putFile(path string, source io.ReadSeeker) error {
|
||||
func (storage *PublishedStorage) putFile(path string, source io.ReadSeeker, sourceMD5 string) error {
|
||||
|
||||
params := &s3.PutObjectInput{
|
||||
Bucket: aws.String(storage.bucket),
|
||||
@@ -165,6 +181,11 @@ func (storage *PublishedStorage) putFile(path string, source io.ReadSeeker) erro
|
||||
if storage.encryptionMethod != "" {
|
||||
params.ServerSideEncryption = aws.String(storage.encryptionMethod)
|
||||
}
|
||||
if sourceMD5 != "" {
|
||||
params.Metadata = map[string]*string{
|
||||
"Md5": aws.String(sourceMD5),
|
||||
}
|
||||
}
|
||||
|
||||
_, err := storage.s3.PutObject(params)
|
||||
if err != nil {
|
||||
@@ -177,7 +198,7 @@ func (storage *PublishedStorage) putFile(path string, source io.ReadSeeker) erro
|
||||
return err
|
||||
}
|
||||
|
||||
return storage.putFile(strings.Replace(path, "+", " ", -1), source)
|
||||
return storage.putFile(strings.Replace(path, "+", " ", -1), source, sourceMD5)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -298,6 +319,17 @@ func (storage *PublishedStorage) LinkFromPool(publishedDirectory, fileName strin
|
||||
sourceMD5 := sourceChecksums.MD5
|
||||
|
||||
if exists {
|
||||
if len(destinationMD5) != 32 {
|
||||
// doesn’t look like a valid MD5,
|
||||
// attempt to fetch one from the metadata
|
||||
var err error
|
||||
destinationMD5, err = storage.getMD5(relPath)
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, fmt.Sprintf("error verifying MD5 for %s: %s", storage, poolPath))
|
||||
return err
|
||||
}
|
||||
storage.pathCache[relPath] = destinationMD5
|
||||
}
|
||||
if sourceMD5 == "" {
|
||||
return fmt.Errorf("unable to compare object, MD5 checksum missing")
|
||||
}
|
||||
@@ -318,7 +350,7 @@ func (storage *PublishedStorage) LinkFromPool(publishedDirectory, fileName strin
|
||||
}
|
||||
defer source.Close()
|
||||
|
||||
err = storage.putFile(relPath, source)
|
||||
err = storage.putFile(relPath, source, sourceMD5)
|
||||
if err == nil {
|
||||
storage.pathCache[relPath] = sourceMD5
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user