@@ -171,7 +171,7 @@ func remoteToLocal_file(jptm IJobPartTransferMgr, p pipeline.Pipeline, pacer pac
171
171
// to correct name.
172
172
pseudoId := common .NewPseudoChunkIDForWholeFile (info .Source )
173
173
jptm .LogChunkStatus (pseudoId , common .EWaitReason .CreateLocalFile ())
174
- dstFile , err = createDestinationFile (jptm , info .getTempDownloadPath (), fileSize , writeThrough )
174
+ dstFile , err = createDestinationFile (jptm , info .getDownloadPath (), fileSize , writeThrough )
175
175
jptm .LogChunkStatus (pseudoId , common .EWaitReason .ChunkDone ()) // normal setting to done doesn't apply to these pseudo ids
176
176
if err != nil {
177
177
failFileCreation (err )
@@ -342,7 +342,7 @@ func epilogueWithCleanupDownload(jptm IJobPartTransferMgr, dl downloader, active
342
342
343
343
// check length if enabled (except for dev null and decompression case, where that's impossible)
344
344
if info .DestLengthValidation && info .Destination != common .Dev_Null && ! jptm .ShouldDecompress () {
345
- fi , err := common .OSStat (info .getTempDownloadPath ())
345
+ fi , err := common .OSStat (info .getDownloadPath ())
346
346
347
347
if err != nil {
348
348
jptm .FailActiveDownload ("Download length check" , err )
@@ -351,14 +351,16 @@ func epilogueWithCleanupDownload(jptm IJobPartTransferMgr, dl downloader, active
351
351
}
352
352
}
353
353
354
- //Rename back to original name. At this point, we're sure the file is completely
354
+ //check if we need to rename back to original name. At this point, we're sure the file is completely
355
355
//downloaded and not corrupt. Infact, post this point we should only log errors and
356
356
//not fail the transfer.
357
- if err == nil && ! strings .EqualFold (info .Destination , common .Dev_Null ) {
358
- renameErr := os .Rename (info .getTempDownloadPath (), info .Destination )
357
+ renameNecessary := ! strings .EqualFold (info .getDownloadPath (), info .Destination ) &&
358
+ ! strings .EqualFold (info .Destination , common .Dev_Null )
359
+ if err == nil && renameNecessary {
360
+ renameErr := os .Rename (info .getDownloadPath (), info .Destination )
359
361
if renameErr != nil {
360
362
jptm .LogError (info .Destination , fmt .Sprintf (
361
- "Failed to rename. File at %s" , info .getTempDownloadPath ()), renameErr )
363
+ "Failed to rename. File at %s" , info .getDownloadPath ()), renameErr )
362
364
}
363
365
}
364
366
}
@@ -461,19 +463,23 @@ func tryDeleteFile(info TransferInfo, jptm IJobPartTransferMgr) {
461
463
return
462
464
}
463
465
464
- err := deleteFile (info .getTempDownloadPath ())
466
+ err := deleteFile (info .getDownloadPath ())
465
467
if err != nil {
466
468
// If there was an error deleting the file, log the error
467
469
jptm .LogError (info .Destination , "Delete File Error " , err )
468
470
}
469
471
}
470
472
471
- //Returns the path of temp file to be downloaded. The paths is in format
473
+ // Returns the path of file to be downloaded. If we want to
474
+ // download to a temp path we return a temp paht in format
472
475
// /actual/parent/path/.azDownload-<jobID>-<actualFileName>
473
- func (info * TransferInfo ) getTempDownloadPath () string {
474
- parent , fileName := filepath .Split (info .Destination )
475
- fileName = fmt .Sprintf (azcopyTempDownloadPrefix , info .JobID .String ()) + fileName
476
- return filepath .Join (parent , fileName )
476
+ func (info * TransferInfo ) getDownloadPath () string {
477
+ if common .GetLifecycleMgr ().DownloadToTempPath () {
478
+ parent , fileName := filepath .Split (info .Destination )
479
+ fileName = fmt .Sprintf (azcopyTempDownloadPrefix , info .JobID .String ()) + fileName
480
+ return filepath .Join (parent , fileName )
481
+ }
482
+ return info .Destination
477
483
}
478
484
479
485
// conforms to io.Writer and io.Closer
0 commit comments