Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions base/cvd/cuttlefish/common/libs/utils/files.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ Result<std::string> CreateHardLink(const std::string& target,
"link() failed trying to create hardlink from \"{}\" to \"{}\" "
"with error: {}",
target, hardlink, strerror(errno));
VLOG(1) << "Created hard link from \"" << target << "\" to \"" << hardlink
<< "\"";
Comment on lines +142 to +143
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the logs here be at VLOG(0) level so they at least show up in the fetch.log file? At least I think that's what the cutoff is.

return hardlink;
}

Expand Down
37 changes: 13 additions & 24 deletions base/cvd/cuttlefish/host/libs/web/caching_build_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ Result<CachingPaths> ConstructCachePaths(const std::string& cache_base,
return result;
}

bool IsInCache(const std::string& filepath) {
const bool exists = FileExists(filepath);
if (exists) {
VLOG(1) << "Found \"" << filepath << "\" in cache";
} else {
VLOG(1) << "\"" << filepath << "\" not in cache";
}
return exists;
}

} // namespace

Result<bool> CanCache(const std::string& target_directory,
Expand Down Expand Up @@ -100,16 +110,9 @@ Result<std::string> CachingBuildApi::DownloadFile(
const std::string& artifact_name) {
const auto paths = CF_EXPECT(ConstructCachePaths(cache_base_path_, build,
target_directory, artifact_name));
if (!FileExists(paths.cache_artifact)) {
LOG(INFO) << artifact_name << " not in cache. Downloading to "
<< paths.build_cache;
if (!IsInCache(paths.cache_artifact)) {
CF_EXPECT(build_api_.DownloadFile(build, paths.build_cache, artifact_name));
} else {
LOG(INFO) << "Found " << artifact_name << " in cache at "
<< paths.cache_artifact;
}
LOG(INFO) << "Linking " << paths.cache_artifact << " to "
<< paths.target_artifact;
return CF_EXPECT(CreateHardLink(paths.cache_artifact, paths.target_artifact,
kOverwriteExistingFile));
}
Expand All @@ -120,35 +123,21 @@ Result<std::string> CachingBuildApi::DownloadFileWithBackup(
const auto paths =
CF_EXPECT(ConstructCachePaths(cache_base_path_, build, target_directory,
artifact_name, backup_artifact_name));
if (FileExists(paths.cache_artifact)) {
LOG(INFO) << "Found " << artifact_name << " in cache at "
<< paths.cache_artifact;
LOG(INFO) << "Linking " << paths.cache_artifact << " to "
<< paths.target_artifact;
if (IsInCache(paths.cache_artifact)) {
return CF_EXPECT(CreateHardLink(paths.cache_artifact, paths.target_artifact,
kOverwriteExistingFile));
}
if (FileExists(paths.cache_backup_artifact)) {
LOG(INFO) << "Found " << backup_artifact_name << " in cache at "
<< paths.cache_backup_artifact;
LOG(INFO) << "Linking " << paths.cache_backup_artifact << " to "
<< paths.target_backup_artifact;
if (IsInCache(paths.cache_backup_artifact)) {
return CF_EXPECT(CreateHardLink(paths.cache_backup_artifact,
paths.target_backup_artifact,
kOverwriteExistingFile));
}
LOG(INFO) << artifact_name << " and " << backup_artifact_name
<< " not in cache. Downloading to " << paths.build_cache;
const auto artifact_filepath = CF_EXPECT(build_api_.DownloadFileWithBackup(
build, paths.build_cache, artifact_name, backup_artifact_name));
if (absl::EndsWith(artifact_filepath, artifact_name)) {
LOG(INFO) << "Linking " << paths.cache_artifact << " to "
<< paths.target_artifact;
return CF_EXPECT(CreateHardLink(paths.cache_artifact, paths.target_artifact,
kOverwriteExistingFile));
}
LOG(INFO) << "Linking " << paths.cache_backup_artifact << " to "
<< paths.target_backup_artifact;
return CF_EXPECT(CreateHardLink(paths.cache_backup_artifact,
paths.target_backup_artifact));
}
Expand Down
Loading