-
Notifications
You must be signed in to change notification settings - Fork 23
/
push.go
893 lines (810 loc) · 20.5 KB
/
push.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
package txlib
import (
"errors"
"fmt"
"os"
"path/filepath"
"sort"
"strings"
"time"
"github.com/fatih/color"
"github.com/transifex/cli/internal/txlib/config"
"github.com/transifex/cli/pkg/jsonapi"
"github.com/transifex/cli/pkg/txapi"
"github.com/transifex/cli/pkg/worker_pool"
)
type PushCommandArguments struct {
Source bool
Translation bool
Force bool
Skip bool
Xliff bool
Languages []string
ResourceIds []string
UseGitTimestamps bool
Branch string
Base string
All bool
Workers int
Silent bool
ReplaceEditedStrings bool
KeepTranslations bool
}
func PushCommand(
cfg *config.Config,
api jsonapi.Connection,
args PushCommandArguments,
) error {
args.Branch = figureOutBranch(args.Branch)
cfgResources, err := figureOutResources(args.ResourceIds, cfg)
if err != nil {
return err
}
applyBranchToResources(cfgResources, args.Branch)
sort.Slice(cfgResources, func(i, j int) bool {
return cfgResources[i].GetAPv3Id() < cfgResources[j].GetAPv3Id()
})
// Step 1: Resources
if !args.Silent {
fmt.Print("# Getting info about resources\n\n")
}
pool := worker_pool.New(args.Workers, len(cfgResources), args.Silent)
sourceTaskChannel := make(chan *SourceFilePushTask)
translationTaskChannel := make(chan *TranslationFileTask)
targetLanguagesChannel := make(chan TargetLanguageMessage)
for _, cfgResource := range cfgResources {
pool.Add(
&ResourcePushTask{
cfg,
cfgResource,
sourceTaskChannel,
translationTaskChannel,
&api,
args,
targetLanguagesChannel,
},
)
}
pool.Start()
var sourceFileTasks []*SourceFilePushTask
var translationFileTasks []*TranslationFileTask
projects := make(map[string]*jsonapi.Resource)
targetLanguages := make(map[string][]string)
waitChannel := pool.Wait()
exitfor := false
for !exitfor {
select {
case sourceFileTask := <-sourceTaskChannel:
sourceFileTasks = append(sourceFileTasks, sourceFileTask)
case translationFileTask := <-translationTaskChannel:
translationFileTasks = append(translationFileTasks, translationFileTask)
case targetLanguageMessage := <-targetLanguagesChannel:
project := targetLanguageMessage.project
languageId := targetLanguageMessage.languageId
_, exists := projects[project.Id]
if !exists {
projects[project.Id] = project
}
languages, exists := targetLanguages[project.Id]
if !exists {
targetLanguages[project.Id] = []string{}
languages = targetLanguages[project.Id]
}
if !stringSliceContains(languages, languageId) {
targetLanguages[project.Id] = append(
targetLanguages[project.Id],
languageId,
)
}
case <-waitChannel:
exitfor = true
}
}
if pool.IsAborted {
return errors.New("Aborted")
}
if args.Silent {
var names []string
for _, cfgResource := range cfgResources {
names = append(names, fmt.Sprintf(
"%s.%s",
cfgResource.ProjectSlug,
cfgResource.ResourceSlug,
))
}
fmt.Printf("Got info about resources: %s\n", strings.Join(names, ", "))
}
// Step 2: Create missing remote target languages
if len(targetLanguages) > 0 {
if !args.Silent {
fmt.Print("\n# Create missing remote target languages\n\n")
}
pool = worker_pool.New(args.Workers, len(targetLanguages), args.Silent)
for projectId, languages := range targetLanguages {
sort.Slice(languages, func(i, j int) bool {
return languages[i] < languages[j]
})
pool.Add(&LanguagePushTask{projects[projectId], languages, args})
}
pool.Start()
<-pool.Wait()
if pool.IsAborted {
return errors.New("Aborted")
}
if args.Silent {
var names []string
for projectId, languages := range targetLanguages {
parts := strings.Split(projectId, ":")
projectSlug := parts[1]
var languageCodes []string
languageCodes = append(languageCodes, languages...)
names = append(names, fmt.Sprintf(
"%s: %s",
projectSlug,
strings.Join(languageCodes, ", "),
))
}
fmt.Printf(
"Created missing remote target languages: %s\n",
strings.Join(names, ", "),
)
}
}
// Step 3: SourceFiles
if len(sourceFileTasks) > 0 {
if !args.Silent {
fmt.Print("\n# Pushing source files\n\n")
}
sort.Slice(sourceFileTasks, func(i, j int) bool {
return sourceFileTasks[i].resource.Id < sourceFileTasks[j].resource.Id
})
pool = worker_pool.New(args.Workers, len(sourceFileTasks), args.Silent)
for _, sourceFileTask := range sourceFileTasks {
pool.Add(sourceFileTask)
}
pool.Start()
<-pool.Wait()
if pool.IsAborted {
return errors.New("Aborted")
}
if args.Silent {
var names []string
for _, sourceFileTask := range sourceFileTasks {
parts := strings.Split(sourceFileTask.resource.Id, ":")
resourceSlug := parts[5]
names = append(names, resourceSlug)
}
fmt.Printf(
"Pushed source files for: %s\n",
strings.Join(names, ", "),
)
}
}
// Step 4: Translations
if len(translationFileTasks) > 0 {
sort.Slice(translationFileTasks, func(i, j int) bool {
left := translationFileTasks[i]
right := translationFileTasks[j]
if left.resource.Id != right.resource.Id {
return left.resource.Id < right.resource.Id
} else {
return left.languageCode < right.languageCode
}
})
if !args.Silent {
fmt.Print("\n# Pushing translations\n\n")
}
pool = worker_pool.New(args.Workers, len(translationFileTasks), args.Silent)
for _, translationFileTask := range translationFileTasks {
pool.Add(translationFileTask)
}
pool.Start()
<-pool.Wait()
if pool.IsAborted {
return errors.New("Aborted")
}
if args.Silent {
var names []string
for _, translationFileTask := range translationFileTasks {
parts := strings.Split(translationFileTask.resource.Id, ":")
resourceSlug := parts[5]
names = append(names, fmt.Sprintf(
"%s: %s",
resourceSlug,
translationFileTask.languageCode,
))
}
fmt.Printf("Pushed translations: %s\n", strings.Join(names, ", "))
}
}
return nil
}
type TargetLanguageMessage struct {
project *jsonapi.Resource
languageId string
}
type ResourcePushTask struct {
cfg *config.Config
cfgResource *config.Resource
sourceTaskChannel chan *SourceFilePushTask
translationTaskChannel chan *TranslationFileTask
api *jsonapi.Connection
args PushCommandArguments
targetLanguagesChannel chan TargetLanguageMessage
}
func (task *ResourcePushTask) Run(send func(string), abort func()) {
cfg := task.cfg
cfgResource := task.cfgResource
sourceTaskChannel := task.sourceTaskChannel
translationTaskChannel := task.translationTaskChannel
api := task.api
args := task.args
targetLanguagesChannel := task.targetLanguagesChannel
sendMessage := func(body string, force bool) {
if args.Silent && !force {
return
}
message := fmt.Sprintf(
"%s.%s - %s",
cfgResource.ProjectSlug,
cfgResource.ResourceSlug,
body,
)
if !args.Silent {
message = truncateMessage(message)
}
send(message)
}
sendMessage("Getting info", false)
resource, err := txapi.GetResourceById(api, cfgResource.GetAPv3Id())
if err != nil {
sendMessage(fmt.Sprintf("Error while fetching resource: %s", err), true)
if !args.Skip {
abort()
}
return
}
resourceIsNew := resource == nil
if resourceIsNew {
if args.Translation && !args.Source {
sendMessage(
"You are attempting to push translations for a resource that doesn't "+
"exist yet",
true,
)
if !args.Skip {
abort()
}
return
}
sendMessage("Resource does not exist; creating", false)
if cfgResource.Type == "" {
sendMessage("Error: Cannot create resource, i18n type is unknown", true)
if !args.Skip {
abort()
}
return
}
var resourceName string
var baseResourceId string
if args.Branch == "" {
resourceName = cfgResource.GetName()
} else {
resourceName = fmt.Sprintf(
"%s (branch %s)",
cfgResource.GetName(),
args.Branch,
)
baseResourceSlug := getBaseResourceSlug(cfgResource, args.Branch, args.Base)
baseResourceId = fmt.Sprintf(
"o:%s:p:%s:r:%s",
cfgResource.OrganizationSlug,
cfgResource.ProjectSlug,
baseResourceSlug,
)
baseResource, err := txapi.GetResourceById(api, baseResourceId)
if err != nil {
sendMessage(fmt.Sprintf("Error while fetching base resource: %s", err), true)
if !args.Skip {
abort()
}
return
}
if args.Base != "-1" {
if baseResource == nil {
sendMessage(fmt.Sprintf("Base Resource does not exist: %s", baseResourceId), true)
if !args.Skip {
abort()
}
return
}
} else {
if baseResource == nil {
baseResourceId = ""
}
}
}
resource, err = txapi.CreateResource(
api,
fmt.Sprintf(
"o:%s:p:%s",
cfgResource.OrganizationSlug,
cfgResource.ProjectSlug,
),
resourceName,
cfgResource.ResourceSlug,
cfgResource.Type,
baseResourceId,
)
if err != nil {
sendMessage(fmt.Sprintf("Error while creating resource, %s", err), true)
if !args.Skip {
abort()
}
return
}
} else {
if args.Branch != "" && args.Base != "-1" {
baseResourceSlug := getBaseResourceSlug(cfgResource, args.Branch, args.Base)
baseResourceId := fmt.Sprintf(
"o:%s:p:%s:r:%s",
cfgResource.OrganizationSlug,
cfgResource.ProjectSlug,
baseResourceSlug,
)
applyBranchToResources([]*config.Resource{cfgResource}, args.Branch)
resource.SetRelated("base", &jsonapi.Resource{Type: "resources", Id: baseResourceId})
err = resource.Save([]string{"base"})
if err != nil {
sendMessage(err.Error(), true)
if !args.Skip {
abort()
}
return
}
}
}
sendMessage("Getting stats", false)
projectRelationship, err := resource.Fetch("project")
if err != nil {
sendMessage(err.Error(), true)
if !args.Skip {
abort()
}
return
}
project := projectRelationship.DataSingular
sourceLanguageRelationship, exists := project.Relationships["source_language"]
if !exists {
sendMessage(
"Invalid API response, project does not have a 'source_language' "+
"relationship",
true,
)
if !args.Skip {
abort()
}
return
}
sourceLanguage := sourceLanguageRelationship.DataSingular
var remoteStats map[string]*jsonapi.Resource
if args.Translation {
remoteStats, err = txapi.GetResourceStats(api, resource, nil)
} else {
remoteStats, err = txapi.GetResourceStats(api, resource, sourceLanguage)
}
if err != nil {
sendMessage(fmt.Sprintf("Error while fetching stats, %s", err), true)
if !args.Skip {
abort()
}
return
}
if args.Source || !args.Translation {
sourceTaskChannel <- &SourceFilePushTask{
api,
resource,
cfgResource.SourceFile,
remoteStats[sourceLanguage.Id],
args,
resourceIsNew,
args.ReplaceEditedStrings || cfgResource.ReplaceEditedStrings,
args.KeepTranslations || cfgResource.KeepTranslations,
}
}
if args.Translation { // -t flag is set
localToRemoteLanguageMappings := makeLocalToRemoteLanguageMappings(
*cfg,
*cfgResource,
)
overrides := cfgResource.Overrides
sendMessage("Fetching remote languages", false)
curDir, err := os.Getwd()
if err != nil {
sendMessage(err.Error(), true)
if !args.Skip {
abort()
}
return
}
fileFilter := cfgResource.FileFilter
err = checkFileFilter(fileFilter)
if err != nil {
sendMessage(err.Error(), true)
if !args.Skip {
abort()
}
return
}
if args.Xliff {
fileFilter = fmt.Sprintf("%s.xlf", fileFilter)
}
paths, newLanguageCodes, err := getFilesToPush(
curDir, fileFilter, localToRemoteLanguageMappings,
remoteStats, overrides, args, resourceIsNew,
)
if err != nil {
sendMessage(err.Error(), true)
if !args.Skip {
abort()
}
return
}
allLanguages, err := txapi.GetLanguages(api)
if err != nil {
sendMessage(err.Error(), true)
abort()
return
}
for _, languageCode := range newLanguageCodes {
_, exists := allLanguages[languageCode]
if !exists || fmt.Sprintf("l:%s", languageCode) == sourceLanguage.Id {
continue
}
targetLanguagesChannel <- TargetLanguageMessage{project, languageCode}
}
for languageCode, path := range paths {
_, exists := allLanguages[languageCode]
if !exists || fmt.Sprintf("l:%s", languageCode) == sourceLanguage.Id {
continue
}
translationTaskChannel <- &TranslationFileTask{
api,
languageCode,
path,
resource,
args,
remoteStats,
resourceIsNew,
}
}
}
sendMessage("Done", false)
}
type LanguagePushTask struct {
project *jsonapi.Resource
languages []string
args PushCommandArguments
}
func (task *LanguagePushTask) Run(send func(string), abort func()) {
project := task.project
languages := task.languages
args := task.args
parts := strings.Split(project.Id, ":")
sendMessage := func(body string, force bool) {
if args.Silent && !force {
return
}
message := fmt.Sprintf(
"%s (%s) - %s",
parts[3],
strings.Join(languages, ", "),
body,
)
if !args.Silent {
message = truncateMessage(message)
}
send(message)
}
sendMessage("Pushing", false)
var payload []*jsonapi.Resource
for _, language := range languages {
payload = append(payload, &jsonapi.Resource{
Type: "languages",
Id: fmt.Sprintf("l:%s", language),
})
}
err := project.Add("languages", payload)
if err != nil {
sendMessage(err.Error(), true)
abort()
return
}
sendMessage("Done", false)
}
type SourceFilePushTask struct {
api *jsonapi.Connection
resource *jsonapi.Resource
sourceFile string
remoteStats *jsonapi.Resource
args PushCommandArguments
resourceIsNew bool
replaceEditedStrings bool
keepTranslations bool
}
func (task *SourceFilePushTask) Run(send func(string), abort func()) {
api := task.api
resource := task.resource
sourceFile := task.sourceFile
remoteStats := task.remoteStats
args := task.args
resourceIsNew := task.resourceIsNew
replaceEditedStrings := task.replaceEditedStrings
keepTranslations := task.keepTranslations
parts := strings.Split(resource.Id, ":")
sendMessage := func(body string, force bool) {
if args.Silent && !force {
return
}
message := fmt.Sprintf("%s.%s - %s", parts[3], parts[5], body)
if !args.Silent {
message = truncateMessage(message)
}
send(message)
}
file, err := os.Open(sourceFile)
if err != nil {
sendMessage(err.Error(), true)
if !args.Skip {
abort()
}
return
}
defer file.Close()
// Only check timestamps if -f isn't set and if resource isn't new
if !args.Force && !resourceIsNew {
// Project should already be pre-fetched
skip, err := shouldSkipPush(
sourceFile, remoteStats, args.UseGitTimestamps,
)
if skip {
sendMessage("Skipping", false)
return
}
if err != nil {
sendMessage(err.Error(), true)
if !args.Skip {
abort()
}
return
}
}
// Uploading file
var sourceUpload *jsonapi.Resource
err = handleRetry(
func() error {
var err error
sourceUpload, err = txapi.UploadSource(
api, resource, file, replaceEditedStrings, keepTranslations,
)
return err
},
"Uploading file",
func(msg string) { sendMessage(msg, false) },
)
if err != nil {
sendMessage(err.Error(), true)
if !args.Skip {
abort()
}
return
}
// Polling
err = handleRetry(
func() error {
return txapi.PollSourceUpload(sourceUpload)
},
"",
func(msg string) { sendMessage(msg, false) },
)
if err != nil {
sendMessage(err.Error(), true)
if !args.Skip {
abort()
}
return
}
sendMessage("Done", false)
}
type TranslationFileTask struct {
api *jsonapi.Connection
languageCode string
path string
resource *jsonapi.Resource
args PushCommandArguments
remoteStats map[string]*jsonapi.Resource
resourceIsNew bool
}
func (task *TranslationFileTask) Run(send func(string), abort func()) {
api := task.api
languageCode := task.languageCode
path := task.path
resource := task.resource
args := task.args
remoteStats := task.remoteStats
resourceIsNew := task.resourceIsNew
parts := strings.Split(resource.Id, ":")
cyan := color.New(color.FgCyan).SprintFunc()
sendMessage := func(body string, force bool) {
if args.Silent && !force {
return
}
message := fmt.Sprintf(
"%s.%s %s - %s", parts[3], parts[5],
cyan("["+languageCode+"]"), body,
)
if !args.Silent {
message = truncateMessage(message)
}
send(message)
}
// Only check timestamps if -f isn't set and if resource isn't new
if !args.Force && !resourceIsNew {
languageId := fmt.Sprintf("l:%s", languageCode)
remoteStat, exists := remoteStats[languageId]
if exists {
skip, err := shouldSkipPush(path, remoteStat, args.UseGitTimestamps)
if err != nil {
sendMessage(err.Error(), true)
if !args.Skip {
abort()
}
return
}
if skip {
sendMessage("Skipping because remote file is newer than local", false)
return
}
}
}
// Uploading file
var upload *jsonapi.Resource
err := handleRetry(
func() error {
var err error
upload, err = pushTranslation(
api, languageCode, path, resource, args,
)
return err
},
"Uploading file",
func(msg string) { sendMessage(msg, false) },
)
if err != nil {
sendMessage(err.Error(), true)
if !args.Skip {
abort()
}
return
}
// Polling
err = handleRetry(
func() error {
return txapi.PollTranslationUpload(upload)
},
"",
func(msg string) { sendMessage(msg, false) },
)
if err != nil {
sendMessage(err.Error(), true)
if !args.Skip {
abort()
}
return
}
sendMessage("Done", false)
}
func getFilesToPush(
curDir, fileFilter string,
localToRemoteLanguageMappings map[string]string,
remoteStats map[string]*jsonapi.Resource,
overrides map[string]string,
args PushCommandArguments,
resourceIsNew bool,
) (map[string]string, []string, error) {
paths := make(map[string]string)
var newLanguageCodes []string
allLocalLanguages := searchFileFilter(curDir, fileFilter)
if len(overrides) > 0 {
for languageCode, customPath := range overrides {
// Add the Resource file filter overrides per lang
path := filepath.Join(curDir, customPath)
// In case of xliff/json add the extension
if args.Xliff {
path = fmt.Sprintf("%s.xlf", path)
}
allLocalLanguages[languageCode] = path
}
}
for localLanguageCode, path := range allLocalLanguages {
remoteLanguageCode, exists := localToRemoteLanguageMappings[localLanguageCode]
if !exists {
remoteLanguageCode = localLanguageCode
}
// if -l is set and the language is not in one of the languages, we
// must skip
if len(args.Languages) > 0 &&
(!stringSliceContains(args.Languages, localLanguageCode) &&
!stringSliceContains(args.Languages, remoteLanguageCode)) {
continue
}
remoteLanguageId := fmt.Sprintf("l:%s", remoteLanguageCode)
_, exists = remoteStats[remoteLanguageId]
if exists {
paths[remoteLanguageCode] = path
} else {
// if --all is set or -l is set and the code is in one of the
// languages, we need to create the remote language
if args.All || (len(args.Languages) > 0 &&
(stringSliceContains(args.Languages, localLanguageCode) ||
stringSliceContains(args.Languages, remoteLanguageCode))) {
paths[remoteLanguageCode] = path
newLanguageCodes = append(newLanguageCodes, remoteLanguageCode)
}
continue
}
}
return paths, newLanguageCodes, nil
}
func pushTranslation(
api *jsonapi.Connection,
languageCode, path string,
resource *jsonapi.Resource,
args PushCommandArguments,
) (*jsonapi.Resource, error) {
file, err := os.Open(path)
if err != nil {
return nil, err
}
defer file.Close()
language := &jsonapi.Resource{
API: api,
Type: "languages",
Id: fmt.Sprintf("l:%s", languageCode),
}
upload, err := txapi.UploadTranslation(api, resource, language, file, args.Xliff)
if err != nil {
return nil, err
}
return upload, nil
}
func shouldSkipPush(
path string, remoteStat *jsonapi.Resource, useGitTimestamps bool,
) (bool, error) {
var localTime time.Time
if useGitTimestamps {
localTime = getLastCommitDate(path)
if localTime == (time.Time{}) {
return shouldSkipPush(path, remoteStat, false)
}
} else {
localStat, err := os.Stat(path)
if err != nil {
return false, err
}
localTime = localStat.ModTime().UTC()
}
var remoteStatAttributes txapi.ResourceLanguageStatsAttributes
err := remoteStat.MapAttributes(&remoteStatAttributes)
if err != nil {
return false, err
}
remoteTime, err := time.Parse(time.RFC3339,
remoteStatAttributes.LastUpdate)
if err != nil {
return false, err
}
// Don't push if local file is older than remote
// resource-language
return localTime.Before(remoteTime), nil
}