-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathprogram_version_storage.cpp
More file actions
45 lines (38 loc) · 1.05 KB
/
program_version_storage.cpp
File metadata and controls
45 lines (38 loc) · 1.05 KB
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
// Copyright (C) 2017-2018 Egor Pugin <[email protected]>
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#include "program_version_storage.h"
#include "file.h"
#include <fstream>
namespace sw
{
ProgramVersionStorage::ProgramVersionStorage(const path &fn)
: fn(fn)
{
path p;
String v;
time_t t;
std::ifstream ifile(fn);
while (1)
{
ifile >> p;
if (!ifile)
break;
ifile >> v;
ifile >> t;
if (!fs::exists(p))
continue;
auto lwt = fs::last_write_time(p);
if (t && file_time_type2time_t(lwt) <= t)
versions[p] = {v,lwt};
}
}
ProgramVersionStorage::~ProgramVersionStorage()
{
std::ofstream ofile(fn);
for (auto &[p, v] : std::map<path, ProgramInfo>(versions.begin(), versions.end()))
ofile << p << " " << v.v.toString() << " " << file_time_type2time_t(v.t) << "\n";
}
}