kacarmichael 309eeef59a
Some checks failed
Build Go Binaries / build (push) Has been cancelled
Health/status http endpoint, logging
2026-08-06 01:24:29 -05:00

40 lines
1.1 KiB
Go

package transfer
import (
"context"
"fmt"
"log"
"m3u8-downloader/pkg/logging"
"m3u8-downloader/pkg/nas"
"os"
"path/filepath"
)
func TransferFile(nt *nas.NASService, ctx context.Context, item *TransferItem) error {
destPath := filepath.Join(nt.Config.Path, item.DestinationPath)
destDir := filepath.Dir(destPath)
if err := nt.EnsureDirectoryExists(destDir); err != nil {
return fmt.Errorf("Failed to create directory %s: %w", destDir, err)
}
transferCtx, cancel := context.WithTimeout(ctx, nt.Config.Timeout)
defer cancel()
if err := nt.CopyFile(transferCtx, item.SourcePath, destPath); err != nil {
return fmt.Errorf("Failed to copy file %s to %s: %w", item.SourcePath, destPath, err)
}
if nt.Config.VerifySize {
if err := nt.VerifyTransfer(item.SourcePath, destPath); err != nil {
os.Remove(destPath)
return fmt.Errorf("Failed to verify transfer: %w", err)
}
}
log.Printf("File transfer completed: %s -> %s", item.SourcePath, destPath)
logging.MustGetFactory().Transfer.Debug("nas copy completed", logging.KeyFile, item.SourcePath, "dest", destPath)
return nil
}