• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

PredatorCZ / PreCore / 573

18 Nov 2025 06:14PM UTC coverage: 51.767% (-0.5%) from 52.235%
573

push

github

PredatorCZ
coverage upload can fail

4131 of 7980 relevant lines covered (51.77%)

11428.98 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

62.5
/src/app/tmp_storage.cpp
1
/*  Spike is universal dedicated module handler
2

3
    Copyright 2021-2023 Lukas Cone
4

5
    Licensed under the Apache License, Version 2.0 (the "License");
6
    you may not use this file except in compliance with the License.
7
    You may obtain a copy of the License at
8

9
        http://www.apache.org/licenses/LICENSE-2.0
10

11
    Unless required by applicable law or agreed to in writing, software
12
    distributed under the License is distributed on an "AS IS" BASIS,
13
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
    See the License for the specific language governing permissions and
15
    limitations under the License.
16
*/
17

18
#include "spike/app/tmp_storage.hpp"
19
#include "spike/except.hpp"
20
#include "spike/io/directory_scanner.hpp"
21
#include "spike/io/fileinfo.hpp"
22
#include "spike/io/stat.hpp"
23
#include "spike/master_printer.hpp"
24
#include <chrono>
25
#include <cinttypes>
26
#include <sstream>
27

28
#ifndef _MSC_VER
29
#include <ftw.h>
30
#else
31
#include <filesystem>
32
#endif
33

34
static std::string localPath;
35

36
void InitTempStorage() {
1✔
37
  auto sample = es::GetTempFilename();
38
  AFileInfo sampleParts(sample);
1✔
39
  auto point = std::chrono::system_clock::now() + std::chrono::hours(2);
1✔
40
  std::stringstream str;
1✔
41
  str << sampleParts.GetFolder() << "spike/";
1✔
42
  es::mkdir(str.str());
1✔
43
  str << std::hex << std::chrono::system_clock::to_time_t(point) << '/';
1✔
44
  localPath = str.str();
2✔
45
  es::mkdir(localPath);
46
}
2✔
47

48
static void RemmoveAll(const std::string &path) {
49
#ifndef _MSC_VER
50
  nftw(
1✔
51
      path.data(),
52
      [](const char *pathName, const struct stat *, int, struct FTW *) -> int {
1✔
53
        if (remove(pathName) < 0) {
1✔
54
          printerror("[Spike] Cannot remove: " << pathName);
×
55
          return -1;
×
56
        }
57
        return 0;
58
      },
59
      10, FTW_DEPTH | FTW_MOUNT | FTW_PHYS);
60
#else
61
  std::filesystem::remove_all(std::filesystem::u8path(path));
62
#endif
63
}
1✔
64

65
void CleanTempStorages() {
×
66
  auto sample = es::GetTempFilename();
67
  AFileInfo sampleParts(sample);
×
68
  std::string workDir(std::string(sampleParts.GetFolder()) + "spike/");
×
69
  DirectoryScanner sc;
×
70
  sc.ScanFolders(workDir);
×
71
  auto point = std::chrono::system_clock::now();
×
72

73
  for (auto &s : sc) {
×
74
    std::string_view sw(s);
75
    sw.remove_prefix(workDir.size());
76
    time_t time = std::strtoull(sw.data(), nullptr, 16);
×
77
    auto expiryTimePoint = std::chrono::system_clock::from_time_t(time);
78

79
    if (point >= expiryTimePoint) {
×
80
      RemmoveAll(s);
81
    }
82
  }
83
}
84

85
std::string RequestTempFile() {
1✔
86
  if (localPath.empty()) {
1✔
87
    throw es::RuntimeError(
88
        "InitTempStorage() not called before RequestTempFile()!");
×
89
  }
90

91
  auto point = std::chrono::steady_clock::now();
1✔
92
  std::string retPath = localPath;
93
  char buffer[0x20];
94
  snprintf(buffer, sizeof(buffer), "%" PRIX64,
95
           point.time_since_epoch().count());
96

97
  return retPath + buffer;
2✔
98
}
99

100
void CleanCurrentTempStorage() {
1✔
101
  if (!localPath.empty()) {
1✔
102
    RemmoveAll(localPath);
103
  }
104
}
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc