Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/dev' into fix_xray_sarif
Browse files Browse the repository at this point in the history
  • Loading branch information
attiasas committed Oct 2, 2023
2 parents 2ebdb0c + 29d9856 commit 9ff4e71
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ func handleDelayedArtifactsFiles(filesToConsume []string, base phaseBase, delayU
}

func consumeDelayedArtifactsFiles(pcWrapper *producerConsumerWrapper, filesToConsume []string, uploadChunkChan chan UploadedChunk, base phaseBase, delayHelper delayUploadHelper, errorsChannelMng *ErrorsChannelMng) error {
log.Debug(fmt.Sprintf("Starting to handle delayed artifacts files. Found %d files.", len(filesToConsume)))
for _, filePath := range filesToConsume {
log.Debug("Handling delayed artifacts file: '" + filePath + "'")
delayedArtifactsFile, err := readDelayFile(filePath)
Expand Down
16 changes: 14 additions & 2 deletions artifactory/commands/transferfiles/errorshandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/jfrog/jfrog-client-go/utils/io/fileutils"
"github.com/jfrog/jfrog-client-go/utils/log"
"os"
"path"
"time"
)

Expand Down Expand Up @@ -189,7 +190,7 @@ func (mng *TransferErrorsMng) writeErrorContent(e ExtendedFileUploadStatusRespon
}

func (mng *TransferErrorsMng) writeSkippedErrorContent(e ExtendedFileUploadStatusResponse) error {
log.Debug(fmt.Sprintf("Writing '%s' to file %s", e.Reason, mng.errorWriterMng.skipped.filePath))
logWritingArtifact(e, mng.errorWriterMng.skipped.filePath)
mng.errorWriterMng.skipped.writer.Write(e)
mng.errorWriterMng.skipped.errorCount++
// If file contains maximum number of errors - create and write to a new errors file
Expand All @@ -213,7 +214,7 @@ func (mng *TransferErrorsMng) writeSkippedErrorContent(e ExtendedFileUploadStatu
}

func (mng *TransferErrorsMng) writeRetryableErrorContent(e ExtendedFileUploadStatusResponse) error {
log.Debug(fmt.Sprintf("Writing '%s' to file %s", e.Reason, mng.errorWriterMng.retryable.filePath))
logWritingArtifact(e, mng.errorWriterMng.retryable.filePath)
mng.errorWriterMng.retryable.writer.Write(e)
mng.errorWriterMng.retryable.errorCount++
// If file contains maximum number of errors - create and write to a new errors file
Expand All @@ -236,6 +237,17 @@ func (mng *TransferErrorsMng) writeRetryableErrorContent(e ExtendedFileUploadSta
return nil
}

func logWritingArtifact(e ExtendedFileUploadStatusResponse, errorsFilePath string) {
if log.GetLogger().GetLogLevel() != log.DEBUG {
return
}
msg := fmt.Sprintf("Writing artifact '%s' to errors file '%s'.", path.Join(e.Repo, e.Path, e.Name), errorsFilePath)
if e.Reason != "" {
msg += fmt.Sprintf(" Reason: '%s'.", e.Reason)
}
log.Debug(msg)
}

func (writerMng *errorWriter) closeWriter() error {
// Close content writer and move output file to our working directory
if writerMng.writer == nil {
Expand Down
5 changes: 5 additions & 0 deletions artifactory/commands/transferfiles/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ func runProducerConsumers(pcWrapper *producerConsumerWrapper) (executionErr erro
go func() {
// Wait till notified that the builder has no additional tasks, and close the builder producer consumer.
<-pcWrapper.chunkBuilderProducerConsumer.GetFinishedNotification()
log.Debug("Chunk builder producer consumer has completed all tasks. " +
"All files relevant to this phase were found and added to chunks that are being uploaded...")
pcWrapper.chunkBuilderProducerConsumer.Done()
}()

Expand Down Expand Up @@ -261,6 +263,7 @@ func pollUploads(phaseBase *phaseBase, srcUpService *srcUserPluginService, uploa
}
for i := 0; ; i++ {
if ShouldStop(phaseBase, nil, errorsChannelMng) {
log.Debug("Stop signal received while polling on uploads...")
return
}
time.Sleep(waitTimeBetweenChunkStatusSeconds * time.Second)
Expand All @@ -284,6 +287,7 @@ func pollUploads(phaseBase *phaseBase, srcUpService *srcUserPluginService, uploa
// it will be written to the error channel
if chunksLifeCycleManager.totalChunks == 0 {
if shouldStopPolling(doneChan) {
log.Debug("Stopping to poll on uploads...")
return
}
continue
Expand Down Expand Up @@ -386,6 +390,7 @@ func handleChunksStatuses(phase *phaseBase, chunksStatus *api.UploadChunksStatus
stopped := handleFilesOfCompletedChunk(chunk.Files, errorsChannelMng)
// In case an error occurred while writing errors status's to the errors file - stop transferring.
if stopped {
log.Debug("Stop signal received while handling chunks statuses...")
return true
}
err = setChunkCompletedInRepoSnapshot(phase.stateManager, chunk.Files)
Expand Down

0 comments on commit 9ff4e71

Please sign in to comment.