etl: create a subfolder in datadir for temp files. (#965)

This commit is contained in:
Igor Mandrigin 2020-08-23 11:53:01 +02:00 committed by GitHub
parent 2facf92533
commit 9b81829616
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,6 +6,7 @@ import (
"io"
"io/ioutil"
"os"
"path"
"runtime"
"github.com/ledgerwatch/turbo-geth/common"
@ -31,6 +32,16 @@ func FlushToDisk(encoder Encoder, currentKey []byte, b Buffer, datadir string) (
if b.Len() == 0 {
return nil, nil
}
// if we are going to create files in the system temp dir, we don't need any
// subfolders.
if datadir != "" {
// the folder name stays the same and shared between ETL runs, so we don't need to remove it.
// it actually can make debugging more tricky in case we leak some open files.
datadir = path.Join(datadir, "etl-temp")
if err := os.MkdirAll(datadir, 0755); err != nil {
return nil, err
}
}
bufferFile, err := ioutil.TempFile(datadir, "tg-sync-sortable-buf")
if err != nil {
return nil, err