write scan to unique filename each time

This commit is contained in:
clerie 2024-11-24 18:56:45 +01:00
parent 9e0474a68f
commit 8a230bdc64

11
main.go
View File

@ -2,8 +2,10 @@ package main
import ( import (
"errors" "errors"
"fmt"
"io" "io"
"os" "os"
"path"
"strings" "strings"
"time" "time"
"flag" "flag"
@ -100,8 +102,15 @@ func (driver *ForwarderDriver) GetFile(path string, offset int64) (int64, io.Rea
func (driver *ForwarderDriver) PutFile(destPath string, data io.Reader, appendData bool) (int64, error) { func (driver *ForwarderDriver) PutFile(destPath string, data io.Reader, appendData bool) (int64, error) {
log.Printf("Receiving file %v", destPath) log.Printf("Receiving file %v", destPath)
dest_filename := path.Base(destPath)
t := time.Now()
encrypted_filename := fmt.Sprintf("scan_%04d-%02d-%02d-%02d-%02d_%v.asc", t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), dest_filename)
log.Printf("Writing to %v", encrypted_filename)
log.Printf("Opening output file") log.Printf("Opening output file")
encryptedFile, err := os.Create("file.pdf.asc") encryptedFile, err := os.Create(encrypted_filename)
if err != nil { if err != nil {
log.Printf("Error: %v", err) log.Printf("Error: %v", err)
return 0, err return 0, err