Android-cuttlefish cvd tool
url_download.h
Go to the documentation of this file.
1//
2// Copyright (C) 2026 The Android Open Source Project
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16#pragma once
17
18#include <stdint.h>
19
20#include <optional>
21#include <string>
22#include <vector>
23
24#include "absl/strings/string_view.h"
25
29
30namespace cuttlefish {
31
33 std::string url;
34 std::vector<std::string> headers;
35 std::optional<std::string> if_range; // unset when `url` pins one version
36 std::optional<std::string> version; // set where the origin serves ranges
37 std::optional<uint64_t> size;
38};
39
40// Returns where a download of `version` to `path` keeps its partial file.
41std::string PartialFilePath(const std::string& path, absl::string_view version);
42
43// Returns whether `path` still names the file `fd` holds open. A download
44// that another process finished renames its partial file away, so whoever was
45// waiting for the lock on it wakes up holding a file that is gone.
46Result<bool> HoldsFileAt(Fd& fd, const std::string& path);
47
48// Writes `download` to `path`. Where the version and the size are known, it
49// reads the object in large ranges through `ZipSourceFromUrl` and picks up
50// where an interrupted earlier attempt left off.
52 const UrlDownload& download,
53 const std::string& path);
54
55} // namespace cuttlefish
Definition: fd.h:87
Definition: http_client.h:100
Definition: alloc_driver.h:21
Result< void > DownloadUrlToFile(HttpClient &http_client, const UrlDownload &download, const std::string &path)
Definition: url_download.cpp:162
Result< bool > HoldsFileAt(Fd &fd, const std::string &path)
Definition: url_download.cpp:151
std::string PartialFilePath(const std::string &path, absl::string_view version)
Definition: url_download.cpp:145
tl::expected< T, StackTraceError< E > > Result
Definition: result_type.h:30
uint8_t version
Definition: pairing_connection.cpp:0
Definition: url_download.h:32
std::optional< std::string > if_range
Definition: url_download.h:35
std::string url
Definition: url_download.h:33
std::optional< std::string > version
Definition: url_download.h:36
std::vector< std::string > headers
Definition: url_download.h:34
std::optional< uint64_t > size
Definition: url_download.h:37