forked from stellar/stellar-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFileTransferInfo.h
103 lines (91 loc) · 2.34 KB
/
FileTransferInfo.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#pragma once
// Copyright 2015 Stellar Development Foundation and contributors. Licensed
// under the Apache License, Version 2.0. See the COPYING file at the root
// of this distribution or at http://www.apache.org/licenses/LICENSE-2.0
#include "bucket/Bucket.h"
#include "crypto/Hex.h"
#include "util/Fs.h"
#include "util/Logging.h"
#include "util/TmpDir.h"
#include <string>
namespace stellar
{
extern char const* HISTORY_FILE_TYPE_BUCKET;
extern char const* HISTORY_FILE_TYPE_LEDGER;
extern char const* HISTORY_FILE_TYPE_TRANSACTIONS;
extern char const* HISTORY_FILE_TYPE_RESULTS;
extern char const* HISTORY_FILE_TYPE_SCP;
class FileTransferInfo
{
std::string mType;
std::string mHexDigits;
std::string mLocalPath;
std::string getLocalDir(TmpDir const& localRoot) const;
public:
FileTransferInfo(Bucket const& bucket)
: mType(HISTORY_FILE_TYPE_BUCKET)
, mHexDigits(binToHex(bucket.getHash()))
, mLocalPath(bucket.getFilename())
{
}
FileTransferInfo(TmpDir const& snapDir, std::string const& snapType,
uint32_t checkpointLedger)
: mType(snapType)
, mHexDigits(fs::hexStr(checkpointLedger))
, mLocalPath(getLocalDir(snapDir) + "/" + baseName_nogz())
{
}
FileTransferInfo(TmpDir const& snapDir, std::string const& snapType,
std::string const& hexDigits)
: mType(snapType)
, mHexDigits(hexDigits)
, mLocalPath(getLocalDir(snapDir) + "/" + baseName_nogz())
{
}
std::string
getType() const
{
return mType;
}
std::string
localPath_nogz() const
{
return mLocalPath;
}
std::string
localPath_gz() const
{
return mLocalPath + ".gz";
}
std::string
localPath_gz_tmp() const
{
return mLocalPath + ".gz.tmp";
}
std::string
baseName_nogz() const
{
return fs::baseName(mType, mHexDigits, "xdr");
}
std::string
baseName_gz() const
{
return baseName_nogz() + ".gz";
}
std::string
baseName_gz_tmp() const
{
return baseName_nogz() + ".gz.tmp";
}
std::string
remoteDir() const
{
return fs::remoteDir(mType, mHexDigits);
}
std::string
remoteName() const
{
return fs::remoteName(mType, mHexDigits, "xdr.gz");
}
};
}