Skip to content

Commit

Permalink
Fix issue with minimum-perc skip message
Browse files Browse the repository at this point in the history
Before the fix, we were returning a message that a local file is newer
than the remote one, which wasn't true.

This fix updates the `shouldSkipDownload` to return an additional value
with a message in case it's different than the default one.

Also fixed a typo in readme regarding the `minimum-perc` flag.
  • Loading branch information
codegaze committed Feb 15, 2023
1 parent 7d0983c commit ad9fbbc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ default to taking the filesystem timestamp into account.
you set the `--skip` flag and an upload fails, then the client will simply
print a warning and move on to the next language file.

- `--minimum_perc=MINIMUM_PERC` Specify the minimum translation completion
- `--minimum-perc=MINIMUM_PERC` Specify the minimum translation completion
threshold required in order for a file to be downloaded.

- `--workers/-w` (default 5, max 30): The client will pull files in parallel to improve
Expand Down
26 changes: 15 additions & 11 deletions internal/txlib/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ func (task *FilePullTask) Run(send func(string), abort func()) {
minimumPerc = cfgResource.MinimumPercentage
}
}
shouldSkip, err := shouldSkipDownload(
shouldSkip, feedbackMessage, err := shouldSkipDownload(
filePath,
stats,
args.UseGitTimestamps,
Expand All @@ -497,7 +497,7 @@ func (task *FilePullTask) Run(send func(string), abort func()) {
return
}
if shouldSkip {
sendMessage("Local file is newer than remote, skipping", false)
sendMessage(feedbackMessage, false)
return
}

Expand Down Expand Up @@ -561,13 +561,13 @@ func (task *FilePullTask) Run(send func(string), abort func()) {
func shouldSkipDownload(
path string, remoteStat *jsonapi.Resource, useGitTimestamps bool,
mode string, minimum_perc int, force bool,
) (bool, error) {
) (bool, string, error) {
var localTime time.Time

var feedbackMessage = ""
var remoteStatAttributes txapi.ResourceLanguageStatsAttributes
err := remoteStat.MapAttributes(&remoteStatAttributes)
if err != nil {
return false, err
return false, feedbackMessage, err
}

if minimum_perc > 0 {
Expand All @@ -585,7 +585,8 @@ func shouldSkipDownload(
minimum_perc, actedOnStrings, totalStrings,
)
if skipDueToStringPercentage {
return true, nil
feedbackMessage = "Minimum translation completion threshold not satisfied, skipping"
return true, feedbackMessage, nil
}
}

Expand All @@ -601,24 +602,27 @@ func shouldSkipDownload(
localStat, err := os.Stat(path)
if err != nil {
if os.IsNotExist(err) {
return false, nil
return false, feedbackMessage, nil
}
return false, err
return false, feedbackMessage, err
}
localTime = localStat.ModTime().UTC()
}

remoteTime, err := time.Parse(time.RFC3339,
remoteStatAttributes.LastUpdate)
if err != nil {
return false, err
return false, feedbackMessage, err
}

// Don't pull if local file is newer than remote
// resource-language
return remoteTime.Before(localTime), nil
if remoteTime.Before(localTime) {
feedbackMessage = "Local file is newer than remote, skipping"
}
return remoteTime.Before(localTime), feedbackMessage, nil
}
return false, nil
return false, "", nil
}

func shouldSkipDueToStringPercentage(
Expand Down

0 comments on commit ad9fbbc

Please sign in to comment.