mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-06-07 05:42:42 +00:00
Introduce plusWorkaround: generate copy of file with '+' -> ' ' to workaround S3/apt bug. #98
This commit is contained in:
+10
-4
@@ -19,6 +19,7 @@ type PublishedStorage struct {
|
||||
prefix string
|
||||
storageClass string
|
||||
encryptionMethod string
|
||||
plusWorkaround bool
|
||||
}
|
||||
|
||||
// Check interface
|
||||
@@ -28,7 +29,7 @@ var (
|
||||
|
||||
// NewPublishedStorageRaw creates published storage from raw aws credentials
|
||||
func NewPublishedStorageRaw(auth aws.Auth, region aws.Region, bucket, defaultACL, prefix,
|
||||
storageClass, encryptionMethod string) (*PublishedStorage, error) {
|
||||
storageClass, encryptionMethod string, plusWorkaround bool) (*PublishedStorage, error) {
|
||||
if defaultACL == "" {
|
||||
defaultACL = "private"
|
||||
}
|
||||
@@ -42,7 +43,8 @@ func NewPublishedStorageRaw(auth aws.Auth, region aws.Region, bucket, defaultACL
|
||||
acl: s3.ACL(defaultACL),
|
||||
prefix: prefix,
|
||||
storageClass: storageClass,
|
||||
encryptionMethod: encryptionMethod}
|
||||
encryptionMethod: encryptionMethod,
|
||||
plusWorkaround: plusWorkaround}
|
||||
result.bucket = result.s3.Bucket(bucket)
|
||||
|
||||
return result, nil
|
||||
@@ -51,7 +53,7 @@ func NewPublishedStorageRaw(auth aws.Auth, region aws.Region, bucket, defaultACL
|
||||
// NewPublishedStorage creates new instance of PublishedStorage with specified S3 access
|
||||
// keys, region and bucket name
|
||||
func NewPublishedStorage(accessKey, secretKey, region, bucket, defaultACL, prefix,
|
||||
storageClass, encryptionMethod string) (*PublishedStorage, error) {
|
||||
storageClass, encryptionMethod string, plusWorkaround bool) (*PublishedStorage, error) {
|
||||
auth, err := aws.GetAuth(accessKey, secretKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -62,7 +64,7 @@ func NewPublishedStorage(accessKey, secretKey, region, bucket, defaultACL, prefi
|
||||
return nil, fmt.Errorf("unknown region: %#v", region)
|
||||
}
|
||||
|
||||
return NewPublishedStorageRaw(auth, awsRegion, bucket, defaultACL, prefix, storageClass, encryptionMethod)
|
||||
return NewPublishedStorageRaw(auth, awsRegion, bucket, defaultACL, prefix, storageClass, encryptionMethod, plusWorkaround)
|
||||
}
|
||||
|
||||
// String
|
||||
@@ -108,6 +110,10 @@ func (storage *PublishedStorage) PutFile(path string, sourceFilename string) err
|
||||
if err != nil {
|
||||
return fmt.Errorf("error uploading %s to %s: %s", sourceFilename, storage, err)
|
||||
}
|
||||
|
||||
if storage.plusWorkaround && strings.Index(path, "+") != -1 {
|
||||
return storage.PutFile(strings.Replace(path, "+", " ", -1), sourceFilename)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
+22
-3
@@ -24,10 +24,10 @@ func (s *PublishedStorageSuite) SetUpTest(c *C) {
|
||||
c.Assert(s.srv, NotNil)
|
||||
|
||||
auth, _ := aws.GetAuth("aa", "bb")
|
||||
s.storage, err = NewPublishedStorageRaw(auth, aws.Region{Name: "test-1", S3Endpoint: s.srv.URL(), S3LocationConstraint: true}, "test", "", "", "", "")
|
||||
s.storage, err = NewPublishedStorageRaw(auth, aws.Region{Name: "test-1", S3Endpoint: s.srv.URL(), S3LocationConstraint: true}, "test", "", "", "", "", false)
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
s.prefixedStorage, err = NewPublishedStorageRaw(auth, aws.Region{Name: "test-1", S3Endpoint: s.srv.URL(), S3LocationConstraint: true}, "test", "", "lala", "", "")
|
||||
s.prefixedStorage, err = NewPublishedStorageRaw(auth, aws.Region{Name: "test-1", S3Endpoint: s.srv.URL(), S3LocationConstraint: true}, "test", "", "lala", "", "", false)
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
err = s.storage.s3.Bucket("test").PutBucket("private")
|
||||
@@ -39,7 +39,7 @@ func (s *PublishedStorageSuite) TearDownTest(c *C) {
|
||||
}
|
||||
|
||||
func (s *PublishedStorageSuite) TestNewPublishedStorage(c *C) {
|
||||
stor, err := NewPublishedStorage("aa", "bbb", "", "", "", "", "", "")
|
||||
stor, err := NewPublishedStorage("aa", "bbb", "", "", "", "", "", "", false)
|
||||
c.Check(stor, IsNil)
|
||||
c.Check(err, ErrorMatches, "unknown region: .*")
|
||||
}
|
||||
@@ -64,6 +64,25 @@ func (s *PublishedStorageSuite) TestPutFile(c *C) {
|
||||
c.Check(data, DeepEquals, []byte("welcome to s3!"))
|
||||
}
|
||||
|
||||
func (s *PublishedStorageSuite) TestPutFilePlusWorkaround(c *C) {
|
||||
s.storage.plusWorkaround = true
|
||||
|
||||
dir := c.MkDir()
|
||||
err := ioutil.WriteFile(filepath.Join(dir, "a"), []byte("welcome to s3!"), 0644)
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
err = s.storage.PutFile("a/b+c.txt", filepath.Join(dir, "a"))
|
||||
c.Check(err, IsNil)
|
||||
|
||||
data, err := s.storage.bucket.Get("a/b+c.txt")
|
||||
c.Check(err, IsNil)
|
||||
c.Check(data, DeepEquals, []byte("welcome to s3!"))
|
||||
|
||||
data, err = s.storage.bucket.Get("a/b c.txt")
|
||||
c.Check(err, IsNil)
|
||||
c.Check(data, DeepEquals, []byte("welcome to s3!"))
|
||||
}
|
||||
|
||||
func (s *PublishedStorageSuite) TestFilelist(c *C) {
|
||||
paths := []string{"a", "b", "c", "testa", "test/a", "test/b", "lala/a", "lala/b", "lala/c"}
|
||||
for _, path := range paths {
|
||||
|
||||
Reference in New Issue
Block a user