@@ -104,16 +104,16 @@ func getTokenName(destination *url.URL) (scheme, tokenName string) {
104
104
}
105
105
106
106
// Do writeback to stash using SciTokens
107
- func doWriteBack (source string , destination * url.URL , namespace namespaces.Namespace , recursive bool ) (int64 , error ) {
107
+ func doWriteBack (source string , destination * url.URL , namespace namespaces.Namespace , recursive bool , projectName string ) (int64 , error ) {
108
108
109
109
scitoken_contents , err := getToken (destination , namespace , true , "" )
110
110
if err != nil {
111
111
return 0 , err
112
112
}
113
113
if recursive {
114
- return UploadDirectory (source , destination , scitoken_contents , namespace )
114
+ return UploadDirectory (source , destination , scitoken_contents , namespace , projectName )
115
115
} else {
116
- return UploadFile (source , destination , scitoken_contents , namespace )
116
+ return UploadFile (source , destination , scitoken_contents , namespace , projectName )
117
117
}
118
118
}
119
119
@@ -543,7 +543,7 @@ func DoPut(localObject string, remoteDestination string, recursive bool) (bytesT
543
543
log .Errorln (err )
544
544
return 0 , errors .New ("Failed to get namespace information from source" )
545
545
}
546
- uploadedBytes , err := doWriteBack (localObjectUrl .Path , remoteDestUrl , ns , recursive )
546
+ uploadedBytes , err := doWriteBack (localObjectUrl .Path , remoteDestUrl , ns , recursive , "" )
547
547
AddError (err )
548
548
return uploadedBytes , err
549
549
@@ -646,7 +646,7 @@ func DoGet(remoteObject string, localDestination string, recursive bool) (bytesT
646
646
//Fill out the payload as much as possible
647
647
payload .filename = remoteObjectUrl .Path
648
648
649
- parse_job_ad (payload )
649
+ parse_job_ad (& payload )
650
650
651
651
payload .start1 = time .Now ().Unix ()
652
652
@@ -764,6 +764,9 @@ func DoStashCPSingle(sourceFile string, destination string, methods []string, re
764
764
return 0 , errors .New ("Do not understand destination scheme" )
765
765
}
766
766
767
+ payload := payloadStruct {}
768
+ parse_job_ad (& payload )
769
+
767
770
// Get the namespace of the remote filesystem
768
771
// For write back, it will be the destination
769
772
// For read it will be the source.
@@ -778,7 +781,7 @@ func DoStashCPSingle(sourceFile string, destination string, methods []string, re
778
781
log .Errorln (err )
779
782
return 0 , errors .New ("Failed to get namespace information from destination" )
780
783
}
781
- uploadedBytes , err := doWriteBack (source_url .Path , dest_url , ns , recursive )
784
+ uploadedBytes , err := doWriteBack (source_url .Path , dest_url , ns , recursive , payload . ProjectName )
782
785
AddError (err )
783
786
return uploadedBytes , err
784
787
}
@@ -814,16 +817,11 @@ func DoStashCPSingle(sourceFile string, destination string, methods []string, re
814
817
destination = path .Join (destPath , sourceFilename )
815
818
}
816
819
817
- payload := payloadStruct {}
818
820
payload .version = version
819
821
820
822
//Fill out the payload as much as possible
821
823
payload .filename = source_url .Path
822
824
823
- // ??
824
-
825
- parse_job_ad (payload )
826
-
827
825
payload .start1 = time .Now ().Unix ()
828
826
829
827
// Go thru the download methods
@@ -918,7 +916,7 @@ func get_ips(name string) []string {
918
916
919
917
}
920
918
921
- func parse_job_ad (payload payloadStruct ) { // TODO: needs the payload
919
+ func parse_job_ad (payload * payloadStruct ) {
922
920
923
921
//Parse the .job.ad file for the Owner (username) and ProjectName of the callee.
924
922
@@ -940,18 +938,34 @@ func parse_job_ad(payload payloadStruct) { // TODO: needs the payload
940
938
}
941
939
942
940
// Get all matches from file
943
- classadRegex , e := regexp .Compile (`^\s*(Owner|ProjectName)\s=\s"(.*)"` )
941
+ // Note: This appears to be invalid regex but is the only thing that appears to work. This way it successfully finds our matches
942
+ classadRegex , e := regexp .Compile (`^*\s*(Owner|ProjectName)\s=\s"(.*)"` )
944
943
if e != nil {
945
944
log .Fatal (e )
946
945
}
947
946
948
947
matches := classadRegex .FindAll (b , - 1 )
949
-
950
948
for _ , match := range matches {
951
- if string (match [0 ]) == "Owner" {
952
- payload .Owner = string (match [1 ])
953
- } else if string (match ) == "ProjectName" {
954
- payload .ProjectName = string (match [1 ])
949
+ matchString := strings .TrimSpace (string (match ))
950
+
951
+ if strings .HasPrefix (matchString , "Owner" ) {
952
+ matchParts := strings .Split (strings .TrimSpace (matchString ), "=" )
953
+
954
+ if len (matchParts ) == 2 { // just confirm we get 2 parts of the string
955
+ matchValue := strings .TrimSpace (matchParts [1 ])
956
+ matchValue = strings .Trim (matchValue , "\" " ) //trim any "" around the match if present
957
+ payload .Owner = matchValue
958
+ }
959
+ }
960
+
961
+ if strings .HasPrefix (matchString , "ProjectName" ) {
962
+ matchParts := strings .Split (strings .TrimSpace (matchString ), "=" )
963
+
964
+ if len (matchParts ) == 2 { // just confirm we get 2 parts of the string
965
+ matchValue := strings .TrimSpace (matchParts [1 ])
966
+ matchValue = strings .Trim (matchValue , "\" " ) //trim any "" around the match if present
967
+ payload .ProjectName = matchValue
968
+ }
955
969
}
956
970
}
957
971
0 commit comments