Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: file cache: max size #945

Open
wants to merge 47 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
aeaec40
Initial file api
autoantwort Mar 7, 2023
1f9f19e
Implement win32 and set time
autoantwort Mar 7, 2023
6e5b3ce
Implement for posix and add tests
autoantwort Mar 8, 2023
3866b40
fix windows
autoantwort Mar 8, 2023
323e18f
WIP start implementing stuff
autoantwort Mar 8, 2023
e844636
Messages
autoantwort Mar 10, 2023
09fe44c
Implement most of the functionality. Update of modification dates mis…
autoantwort Mar 12, 2023
0ed4e0b
Add missing entry in schema
autoantwort Mar 12, 2023
0735b64
Merge branch 'main' into feature/file-cache-max-size
autoantwort Mar 16, 2023
eb3d17b
Merge branch 'main' into feature/file-cache-max-size
autoantwort Mar 27, 2023
54244c6
Merge branch 'main' into feature/file-cache-max-size
autoantwort Apr 6, 2023
29aef20
Localize and handle errors
autoantwort Apr 6, 2023
93f71b1
Adapt tests
autoantwort Apr 6, 2023
27bb1a8
Minor fixes
autoantwort Apr 6, 2023
c382c7e
Message map
autoantwort Apr 6, 2023
8f56c38
Merge branch 'main' into feature/file-cache-max-size
autoantwort May 2, 2023
340cc97
Merge branch 'main' into feature/file-cache-max-size
autoantwort May 17, 2023
3f63ec3
Merge branch 'main' into feature/file-cache-max-size
autoantwort May 31, 2023
9503522
Only update when file time is newer
autoantwort Jun 5, 2023
86f36ca
Remove oldest file first.
autoantwort Jun 12, 2023
3526306
Ensure dirs are there.
autoantwort Jun 13, 2023
38a924e
Merge branch 'main' into feature/file-cache-max-size
autoantwort Jun 13, 2023
f81081c
Merge branch 'main' into feature/file-cache-max-size
autoantwort Aug 5, 2023
9b4c64c
Remove duplicated file_size implementation
autoantwort Aug 5, 2023
9f633a8
Filesystem: Allow creation of files without overwriting them
autoantwort Aug 5, 2023
d673966
WIP: Start sync of vcpkg instances
autoantwort Aug 5, 2023
72cdea2
Sync between instances
autoantwort Aug 19, 2023
a3b3926
Delete old sync files after 24 hours
autoantwort Aug 19, 2023
28cd065
Remove Policy "OldestModificationDateUpdateOnAccess" since it was not…
autoantwort Aug 19, 2023
ef6b745
Apply suggestions from code review
autoantwort Aug 22, 2023
6e3a103
Don't change compression level
autoantwort Aug 22, 2023
933dd0a
Fix broken code
autoantwort Aug 22, 2023
5ab77d3
windows: Allow writing to file that is read
autoantwort Aug 28, 2023
2486341
Merge branch 'main' into feature/file-cache-max-size
autoantwort Sep 9, 2023
ebd9d52
Merge branch 'main' into feature/file-cache-max-size
autoantwort Oct 11, 2023
3bd444a
Merge branch 'main' into feature/file-cache-max-size
autoantwort Nov 4, 2023
973cc2c
Skip not complete lines
autoantwort Nov 4, 2023
21b752a
No std::invoke
autoantwort Nov 4, 2023
0078606
Move logic in own class
autoantwort Nov 4, 2023
e75649b
Merge branch 'main' into feature/file-cache-max-size
autoantwort Nov 12, 2023
9250ebf
Merge branch 'main' into feature/file-cache-max-size
autoantwort Dec 13, 2023
796bdb0
Merge branch 'main' into feature/file-cache-max-size
autoantwort Apr 17, 2024
afb8811
Merge branch 'main' into feature/file-cache-max-size
autoantwort Aug 30, 2024
cbc3571
Merge branch 'main' into feature/file-cache-max-size
autoantwort Nov 18, 2024
8797630
Fix message database
autoantwort Nov 18, 2024
7ed2f2e
Merge branch 'main' into feature/file-cache-max-size
autoantwort Dec 25, 2024
7e27e4d
Merge branch 'main' into feature/file-cache-max-size
autoantwort Jan 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions docs/file-cache-settings.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"$id": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/file-cache-settings.schema.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"required": [
"delete-policy"
],
"properties": {
"delete-policy": {
"description": "After which policy objects should be deleted.",
"enum": [
"None",
"OldestAccessDate",
"OldestModificationDate"
]
},
"max-size-in-gb": {
"description": "The maximum size of the cache in gigabytes.",
"type": "number",
"minimum": 0
},
"max-age-in-days": {
"description": "The maximum age of the cache in days.",
"type": "number",
"minimum": 0
},
"keep-available-in-percentage": {
"description": "How much space should be kept available on the disk in percentage.",
"type": "number",
"minimum": 0
}
},
"patternProperties": {
"^\\$": {}
},
"additionalProperties": false
}
26 changes: 25 additions & 1 deletion include/vcpkg/base/files.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,10 @@ namespace vcpkg
{
WriteFilePointer() noexcept;
WriteFilePointer(WriteFilePointer&&) noexcept;
explicit WriteFilePointer(const Path& file_path, Append append, std::error_code& ec);
explicit WriteFilePointer(const Path& file_path, Append append, Overwrite overwrite, std::error_code& ec);
WriteFilePointer& operator=(WriteFilePointer&& other) noexcept;
size_t write(const void* buffer, size_t element_size, size_t element_count) const noexcept;
void flush() const noexcept;
int put(int c) const noexcept;
};

Expand All @@ -129,6 +130,13 @@ namespace vcpkg
// ~ILineReader();
};

struct space_info
{
std::uintmax_t capacity;
std::uintmax_t free;
std::uintmax_t available;
};

struct ReadOnlyFilesystem : ILineReader
{
virtual std::uint64_t file_size(const Path& file_path, std::error_code& ec) const = 0;
Expand Down Expand Up @@ -298,6 +306,22 @@ namespace vcpkg
virtual void copy_symlink(const Path& source, const Path& destination, std::error_code& ec) const = 0;
void copy_symlink(const Path& source, const Path& destination, LineInfo li) const;

virtual int64_t last_write_time_now() const = 0;

virtual int64_t last_write_time(const Path& target, std::error_code& ec) const = 0;
int64_t last_write_time(const Path& target, LineInfo li) const noexcept;

virtual int64_t last_access_time_now() const = 0;

virtual int64_t last_access_time(const Path& target, std::error_code& ec) const = 0;
int64_t last_access_time(const Path& target, LineInfo li) const noexcept;

virtual void last_access_time(const Path& target, int64_t new_time, std::error_code& ec) const = 0;
void last_access_time(const Path& target, int64_t new_time, LineInfo li) const noexcept;

virtual space_info space(const Path& target, std::error_code& ec) const = 0;
space_info space(const Path& target, LineInfo li) const noexcept;

using ReadOnlyFilesystem::current_path;
virtual void current_path(const Path& new_current_path, std::error_code&) const = 0;
void current_path(const Path& new_current_path, LineInfo li) const;
Expand Down
6 changes: 6 additions & 0 deletions include/vcpkg/base/fwd/files.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ namespace vcpkg
YES,
};

enum class Overwrite
{
NO = 0,
YES,
};

struct IgnoreErrors;
struct Path;
struct FilePointer;
Expand Down
1 change: 1 addition & 0 deletions include/vcpkg/base/json.h
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ namespace vcpkg::Json
JsonStyle style;
};

ExpectedL<ParsedJson> parse_file(const ReadOnlyFilesystem&, const Path&, std::error_code& ec);
ExpectedL<ParsedJson> parse(StringView text, StringView origin);
ParsedJson parse_file(LineInfo li, const ReadOnlyFilesystem&, const Path&);
ExpectedL<Json::Object> parse_object(StringView text, StringView origin);
Expand Down
7 changes: 7 additions & 0 deletions include/vcpkg/base/jsonreader.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,13 @@ namespace vcpkg::Json
static const NaturalNumberDeserializer instance;
};

struct PositiveNumberDeserializer final : IDeserializer<double>
{
LocalizedString type_name() const override;
Optional<double> visit_number(Reader&, double value) const override;
static const PositiveNumberDeserializer instance;
};

struct BooleanDeserializer final : IDeserializer<bool>
{
virtual LocalizedString type_name() const override;
Expand Down
5 changes: 5 additions & 0 deletions include/vcpkg/base/message-data.inc.h
Original file line number Diff line number Diff line change
Expand Up @@ -1294,6 +1294,7 @@ DECLARE_MESSAGE(FailedToParseCMakeConsoleOut,
"Failed to parse CMake console output to locate block start/end markers.")
DECLARE_MESSAGE(FailedToParseBaseline, (msg::path), "", "Failed to parse baseline: {path}")
DECLARE_MESSAGE(FailedToParseConfig, (msg::path), "", "Failed to parse configuration: {path}")
DECLARE_MESSAGE(FailedToParseJson, (msg::path), "", "Failed to parse JSON file: {path}")
DECLARE_MESSAGE(FailedToParseVersionFile, (msg::path), "", "Failed to parse version file: {path}")
DECLARE_MESSAGE(FailedToParseNoTopLevelObj, (msg::path), "", "Failed to parse {path}, expected a top-level object.")
DECLARE_MESSAGE(FailedToParseNoVersionsArray, (msg::path), "", "Failed to parse {path}, expected a 'versions' array.")
Expand All @@ -1303,6 +1304,9 @@ DECLARE_MESSAGE(FailedToParseSerializedBinParagraph,
"[sanity check] Failed to parse a serialized binary paragraph.\nPlease open an issue at "
"https://github.com/microsoft/vcpkg, "
"with the following output:\n{error_msg}\nSerialized Binary Paragraph:")
DECLARE_MESSAGE(FailedToParseFileCacheSettings, (msg::path), "", "Failed to parse file cache settings file {path}:")
DECLARE_MESSAGE(FailedToWriteFile, (msg::path, msg::error_msg), "", "Failed to write file {path}: {error_msg}")
DECLARE_MESSAGE(FailedToReadFile, (msg::path, msg::error_msg), "", "Failed to read file {path}: {error_msg}")
DECLARE_MESSAGE(FailedToRunToolToDetermineVersion,
(msg::tool_name, msg::path),
"Additional information, such as the command line output, if any, will be appended on "
Expand Down Expand Up @@ -2313,6 +2317,7 @@ DECLARE_MESSAGE(ParseQualifiedSpecifierNotEofSquareBracket,
(msg::version_spec),
"",
"expected the end of input parsing a package spec; did you mean {version_spec} instead?")
DECLARE_MESSAGE(ParserWarnings, (msg::path), "", "The following warnings were generated while parsing {path}:")
DECLARE_MESSAGE(ParseTripletNotEof,
(),
"",
Expand Down
10 changes: 10 additions & 0 deletions locales/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,10 @@
"FailedToParseCMakeConsoleOut": "Failed to parse CMake console output to locate block start/end markers.",
"FailedToParseConfig": "Failed to parse configuration: {path}",
"_FailedToParseConfig.comment": "An example of {path} is /foo/bar.",
"FailedToParseFileCacheSettings": "Failed to parse file cache settings file {path}:",
"_FailedToParseFileCacheSettings.comment": "An example of {path} is /foo/bar.",
"FailedToParseJson": "Failed to parse JSON file: {path}",
"_FailedToParseJson.comment": "An example of {path} is /foo/bar.",
"FailedToParseNoTopLevelObj": "Failed to parse {path}, expected a top-level object.",
"_FailedToParseNoTopLevelObj.comment": "An example of {path} is /foo/bar.",
"FailedToParseNoVersionsArray": "Failed to parse {path}, expected a 'versions' array.",
Expand All @@ -769,13 +773,17 @@
"_FailedToParseSerializedBinParagraph.comment": "'{error_msg}' is the error message for failing to parse the Binary Paragraph. An example of {error_msg} is File Not Found.",
"FailedToParseVersionFile": "Failed to parse version file: {path}",
"_FailedToParseVersionFile.comment": "An example of {path} is /foo/bar.",
"FailedToReadFile": "Failed to read file {path}: {error_msg}",
"_FailedToReadFile.comment": "An example of {path} is /foo/bar. An example of {error_msg} is File Not Found.",
"FailedToRunToolToDetermineVersion": "Failed to run \"{path}\" to determine the {tool_name} version.",
"_FailedToRunToolToDetermineVersion.comment": "Additional information, such as the command line output, if any, will be appended on the line after this message An example of {tool_name} is aria2. An example of {path} is /foo/bar.",
"FailedToStoreBackToMirror": "Failed to store {path} to {url}.",
"_FailedToStoreBackToMirror.comment": "An example of {path} is /foo/bar. An example of {url} is https://github.com/microsoft/vcpkg.",
"FailedToStoreBinaryCache": "Failed to store binary cache {path}",
"_FailedToStoreBinaryCache.comment": "An example of {path} is /foo/bar.",
"FailedToTakeFileSystemLock": "Failed to take the filesystem lock",
"FailedToWriteFile": "Failed to write file {path}: {error_msg}",
"_FailedToWriteFile.comment": "An example of {path} is /foo/bar. An example of {error_msg} is File Not Found.",
"FailedVendorAuthentication": "One or more {vendor} credential providers failed to authenticate. See '{url}' for more details on how to provide credentials.",
"_FailedVendorAuthentication.comment": "An example of {vendor} is Azure. An example of {url} is https://github.com/microsoft/vcpkg.",
"FetchingBaselineInfo": "Fetching baseline information from {package_name}...",
Expand Down Expand Up @@ -1293,6 +1301,8 @@
"ParseQualifiedSpecifierNotEofSquareBracket": "expected the end of input parsing a package spec; did you mean {version_spec} instead?",
"_ParseQualifiedSpecifierNotEofSquareBracket.comment": "An example of {version_spec} is zlib:[email protected].",
"ParseTripletNotEof": "Invalid triplet name. Triplet names are all lowercase alphanumeric+hyphens.",
"ParserWarnings": "The following warnings were generated while parsing {path}:",
"_ParserWarnings.comment": "An example of {path} is /foo/bar.",
"PathMustBeAbsolute": "Value of environment variable X_VCPKG_REGISTRIES_CACHE is not absolute: {path}",
"_PathMustBeAbsolute.comment": "An example of {path} is /foo/bar.",
"PerformingPostBuildValidation": "Performing post-build validation",
Expand Down
34 changes: 34 additions & 0 deletions src/vcpkg-test/files.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <iostream>
#include <random>
#include <thread>
#include <vector>

#if !defined(_WIN32)
Expand Down Expand Up @@ -163,6 +164,8 @@ namespace
const Filesystem& setup()
{
std::error_code ec;
real_filesystem.remove_all(base_temporary_directory(), ec);
CHECK_EC_ON_FILE(base_temporary_directory(), ec);
real_filesystem.create_directory(base_temporary_directory(), ec);
CHECK_EC_ON_FILE(base_temporary_directory(), ec);

Expand Down Expand Up @@ -948,6 +951,37 @@ TEST_CASE ("copy_symlink", "[files]")
CHECK_EC_ON_FILE(temp_dir, ec);
}

TEST_CASE ("file times", "[files]")
{
urbg_t urbg;

auto& fs = setup();

auto temp_file = base_temporary_directory() / get_random_filename(urbg);
INFO("temp file is: " << temp_file.native());
std::error_code ec;
fs.write_contents(temp_file, "some file contents", VCPKG_LINE_INFO);
auto last_write = fs.last_write_time(temp_file, ec);
CHECK_EC_ON_FILE(temp_file, ec);
std::this_thread::sleep_for(std::chrono::milliseconds(5));
fs.write_contents(temp_file, "new file content", VCPKG_LINE_INFO);
auto last_write_new = fs.last_write_time(temp_file, ec);
CHECK_EC_ON_FILE(temp_file, ec);
REQUIRE(last_write <= last_write_new);
auto last_access = fs.last_access_time(temp_file, ec);
CHECK_EC_ON_FILE(temp_file, ec);
using namespace std::chrono;
last_access -= duration_cast<nanoseconds>(hours(50)).count();
fs.last_access_time(temp_file, last_access, ec);
CHECK_EC_ON_FILE(temp_file, ec);
auto new_last_access = fs.last_access_time(temp_file, ec);
CHECK_EC_ON_FILE(temp_file, ec);
REQUIRE(last_access == new_last_access);

fs.remove(temp_file, ec);
CHECK_EC_ON_FILE(temp_file, ec);
}

TEST_CASE ("LinesCollector", "[files]")
{
using Strings::LinesCollector;
Expand Down
6 changes: 3 additions & 3 deletions src/vcpkg-test/metrics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ TEST_CASE ("payload smoke test", "[metrics]")
"ver": 1,
"name": "Microsoft.ApplicationInsights.Event",
"time": "2022-08-29T15:46:24Z",
"sampleRate": 100.000000,
"sampleRate": 100,
"seq": "0:0",
"iKey": "b4e88960-4393-4dd9-ab8e-97e8fe6d7603",
"flags": 0,
Expand All @@ -242,12 +242,12 @@ TEST_CASE ("payload smoke test", "[metrics]")
"hello"
],
"buildtimes": [
12.000000
12
],
"process_tree": ""
},
"measurements": {
"elapsed_us": 12.000000
"elapsed_us": 12
}
}
}
Expand Down
Loading