blob: c1725ab31a06344c964ecc4471003ee14577ecb7 (
plain) (
blame)
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
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "legacy.h"
#include <vespa/vespalib/io/fileutil.h>
namespace {
bool isFileLegacy(const std::string & configId) {
return configId.compare(0, 5, "file:") == 0;
}
bool isDirLegacy(const std::string & configId) {
return configId.compare(0, 4, "dir:") == 0;
}
const std::string dirNameFromId(const std::string & configId) {
return configId.substr(4);
}
const std::string createFileSpecFromId(const std::string & configId) {
return configId.substr(5);
}
const std::string createBaseId(const std::string & configId) {
std::string::size_type end = configId.find_last_of(".");
return configId.substr(5, end - 5);
}
bool isRawLegacy(const std::string & configId) {
return configId.compare(0, 4, "raw:") == 0;
}
const std::string createRawSpecFromId(const std::string & configId) {
return configId.substr(4);
}
}
namespace config {
bool
isLegacyConfigId(const std::string & configId)
{
return (isRawLegacy(configId) ||
isFileLegacy(configId) ||
isDirLegacy(configId));
}
std::unique_ptr<SourceSpec>
legacyConfigId2Spec(const std::string & configId)
{
if (isFileLegacy(configId)) {
return std::make_unique<FileSpec>(createFileSpecFromId(configId));
} else if (isDirLegacy(configId)) {
return std::make_unique<DirSpec>(dirNameFromId(configId));
} else if (isRawLegacy(configId)) {
return std::make_unique<RawSpec>(createRawSpecFromId(configId));
}
return std::make_unique<ServerSpec>();
}
const std::string
legacyConfigId2ConfigId(const std::string & configId)
{
std::string newId(configId);
if (isFileLegacy(configId)) {
newId = createBaseId(configId);
} else if (isRawLegacy(configId) || isDirLegacy(configId)) {
newId = "";
}
return newId;
}
}
|