@@ -227,10 +227,10 @@ func (p *Plugin) Exec() error {
227227 removed = rem
228228 }
229229 log .WithFields (log.Fields {
230- "name" : match ,
231- "bucket" : p .Bucket ,
232- "target" : target ,
233- "strip_pattern" : p .StripPrefix ,
230+ "name" : match ,
231+ "bucket" : p .Bucket ,
232+ "target" : target ,
233+ "strip_pattern" : p .StripPrefix ,
234234 "removed_prefix" : removed ,
235235 }).Info ("Dry-run: would upload" )
236236 continue
@@ -402,42 +402,42 @@ func resolveSource(sourceDir, source, stripPrefix string) string {
402402 // Remove the leading sourceDir from the source path
403403 path := strings .TrimPrefix (strings .TrimPrefix (source , sourceDir ), "/" )
404404
405- // Add the specified stripPrefix to the resulting path
406- return stripPrefix + path
405+ // Add the specified stripPrefix to the resulting path
406+ return stripPrefix + path
407407}
408408
409409// checks if the source path is a dir
410410func isDir (source string , matches []string ) bool {
411- stat , err := os .Stat (source )
412- if err != nil {
413- return true // should never happen
414- }
415- if stat .IsDir () {
416- count := 0
417- for _ , match := range matches {
418- if strings .HasPrefix (match , source ) {
419- count ++
420- }
421- }
422- if count <= 1 {
423- log .Warnf ("Skipping '%s' since it is a directory. Please use correct glob expression if this is unexpected." , source )
424- }
425- return true
426- }
427- return false
411+ stat , err := os .Stat (source )
412+ if err != nil {
413+ return true // should never happen
414+ }
415+ if stat .IsDir () {
416+ count := 0
417+ for _ , match := range matches {
418+ if strings .HasPrefix (match , source ) {
419+ count ++
420+ }
421+ }
422+ if count <= 1 {
423+ log .Warnf ("Skipping '%s' since it is a directory. Please use correct glob expression if this is unexpected." , source )
424+ }
425+ return true
426+ }
427+ return false
428428}
429429
430430// normalizePath converts the path to a forward slash format and trims the prefix.
431431func normalizePath (path string ) string {
432- return strings .TrimPrefix (filepath .ToSlash (path ), "/" )
432+ return strings .TrimPrefix (filepath .ToSlash (path ), "/" )
433433}
434434
435435// downloadS3Object downloads a single object from S3
436436func (p * Plugin ) downloadS3Object (client * s3.S3 , sourceDir , key , target string ) error {
437- log .WithFields (log.Fields {
438- "bucket" : p .Bucket ,
439- "key" : key ,
440- }).Info ("Getting S3 object" )
437+ log .WithFields (log.Fields {
438+ "bucket" : p .Bucket ,
439+ "key" : key ,
440+ }).Info ("Getting S3 object" )
441441
442442 obj , err := client .GetObject (& s3.GetObjectInput {
443443 Bucket : & p .Bucket ,
@@ -594,18 +594,18 @@ func assumeRoleWithWebIdentity(sess *session.Session, roleArn, roleSessionName,
594594
595595// validateStripPrefix validates a strip prefix pattern with wildcards
596596func validateStripPrefix (pattern string ) error {
597- // Normalize Windows backslashes to forward slashes for validation (OS-independent)
598- pattern = strings .ReplaceAll (pattern , "\\ " , "/" )
597+ // Normalize Windows backslashes to forward slashes for validation (OS-independent)
598+ pattern = strings .ReplaceAll (pattern , "\\ " , "/" )
599599
600- // Pattern must start with /
601- if ! strings .HasPrefix (pattern , "/" ) {
602- return fmt .Errorf ("strip_prefix must start with '/'" )
603- }
600+ // Pattern must start with /
601+ if ! strings .HasPrefix (pattern , "/" ) {
602+ return fmt .Errorf ("strip_prefix must start with '/'" )
603+ }
604604
605- // Reject Windows drive-letter prefixes like C:/...
606- if len (pattern ) >= 2 && pattern [1 ] == ':' {
607- return fmt .Errorf ("strip_prefix must be an absolute POSIX-style path (e.g. '/root/...'), drive letters are not supported" )
608- }
605+ // Reject Windows drive-letter prefixes like C:/...
606+ if len (pattern ) >= 2 && pattern [1 ] == ':' {
607+ return fmt .Errorf ("strip_prefix must be an absolute POSIX-style path (e.g. '/root/...'), drive letters are not supported" )
608+ }
609609
610610 // Check length limit
611611 if len (pattern ) > 256 {
@@ -631,7 +631,7 @@ func validateStripPrefix(pattern string) error {
631631 }
632632 }
633633
634- return nil
634+ return nil
635635}
636636
637637// patternToRegex converts shell-style wildcards to regex
@@ -648,56 +648,56 @@ func patternToRegex(pattern string) (*regexp.Regexp, error) {
648648 // Anchor at start
649649 escaped = "^" + escaped
650650
651- return regexp .Compile (escaped )
651+ return regexp .Compile (escaped )
652652}
653653
654654// stripWildcardPrefixWithRegex strips prefix using wildcard pattern matching, reusing
655655// a precompiled regex when provided. It returns the possibly stripped path, whether
656656// the pattern matched, and any error if stripping would remove the entire key.
657657func stripWildcardPrefixWithRegex (path , pattern string , re * regexp.Regexp ) (string , bool , error ) {
658- if pattern == "" {
659- return path , false , nil
660- }
661-
662- // Normalize paths to forward slashes (OS-independent)
663- path = strings .ReplaceAll (path , "\\ " , "/" )
664- pattern = strings .ReplaceAll (pattern , "\\ " , "/" )
665-
666- // Literal prefix (no wildcards)
667- if ! strings .ContainsAny (pattern , "*?" ) {
668- if ! strings .HasPrefix (path , pattern ) {
669- return path , false , nil
670- }
671- stripped := strings .TrimPrefix (path , pattern )
672- if stripped == "" || stripped == "/" || strings .TrimPrefix (stripped , "/" ) == "" {
673- return path , true , fmt .Errorf ("strip_prefix removes entire path for '%s'" , filepath .Base (path ))
674- }
675- return stripped , true , nil
676- }
677-
678- // Wildcard pattern
679- var err error
680- if re == nil {
681- re , err = patternToRegex (pattern )
682- if err != nil {
683- return path , false , fmt .Errorf ("invalid pattern: %v" , err )
684- }
685- }
686-
687- m := re .FindStringSubmatch (path )
688- if len (m ) == 0 {
689- return path , false , nil
690- }
691- full := m [0 ]
692- stripped := strings .TrimPrefix (path , full )
693- if stripped == "" || stripped == "/" || strings .TrimPrefix (stripped , "/" ) == "" {
694- return path , true , fmt .Errorf ("strip_prefix removes entire path for '%s'" , filepath .Base (path ))
695- }
696- return stripped , true , nil
658+ if pattern == "" {
659+ return path , false , nil
660+ }
661+
662+ // Normalize paths to forward slashes (OS-independent)
663+ path = strings .ReplaceAll (path , "\\ " , "/" )
664+ pattern = strings .ReplaceAll (pattern , "\\ " , "/" )
665+
666+ // Literal prefix (no wildcards)
667+ if ! strings .ContainsAny (pattern , "*?" ) {
668+ if ! strings .HasPrefix (path , pattern ) {
669+ return path , false , nil
670+ }
671+ stripped := strings .TrimPrefix (path , pattern )
672+ if stripped == "" || stripped == "/" || strings .TrimPrefix (stripped , "/" ) == "" {
673+ return path , true , fmt .Errorf ("strip_prefix removes entire path for '%s'" , filepath .Base (path ))
674+ }
675+ return stripped , true , nil
676+ }
677+
678+ // Wildcard pattern
679+ var err error
680+ if re == nil {
681+ re , err = patternToRegex (pattern )
682+ if err != nil {
683+ return path , false , fmt .Errorf ("invalid pattern: %v" , err )
684+ }
685+ }
686+
687+ m := re .FindStringSubmatch (path )
688+ if len (m ) == 0 {
689+ return path , false , nil
690+ }
691+ full := m [0 ]
692+ stripped := strings .TrimPrefix (path , full )
693+ if stripped == "" || stripped == "/" || strings .TrimPrefix (stripped , "/" ) == "" {
694+ return path , true , fmt .Errorf ("strip_prefix removes entire path for '%s'" , filepath .Base (path ))
695+ }
696+ return stripped , true , nil
697697}
698698
699699// stripWildcardPrefix strips prefix using wildcard pattern matching
700700func stripWildcardPrefix (path , pattern string ) (string , error ) {
701- stripped , _ , err := stripWildcardPrefixWithRegex (path , pattern , nil )
702- return stripped , err
701+ stripped , _ , err := stripWildcardPrefixWithRegex (path , pattern , nil )
702+ return stripped , err
703703}
0 commit comments