blob: f2f663816ef41114cf716deff296dd586b8d87a6 [file] [log] [blame]
Tianjie Xu3bbb20f2018-02-27 15:56:11 -08001/*
2 * Copyright (C) 2018 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
17#ifndef _OTAUTIL_OTAUTIL_CACHE_LOCATION_H_
18#define _OTAUTIL_OTAUTIL_CACHE_LOCATION_H_
19
20#include <string>
21
22#include "android-base/macros.h"
23
24// A singleton class to maintain the update related locations. The locations should be only set
25// once at the start of the program.
26class CacheLocation {
27 public:
28 static CacheLocation& location();
29
Tianjie Xu3bbb20f2018-02-27 15:56:11 -080030 // getter and setter functions.
31 std::string cache_temp_source() const {
32 return cache_temp_source_;
33 }
34 void set_cache_temp_source(const std::string& temp_source) {
35 cache_temp_source_ = temp_source;
36 }
37
38 std::string last_command_file() const {
39 return last_command_file_;
40 }
41 void set_last_command_file(const std::string& last_command) {
42 last_command_file_ = last_command;
43 }
44
45 std::string stash_directory_base() const {
46 return stash_directory_base_;
47 }
48 void set_stash_directory_base(const std::string& base) {
49 stash_directory_base_ = base;
50 }
51
52 private:
Tianjie Xub4e3a372018-03-08 12:34:19 -080053 CacheLocation();
Tianjie Xu3bbb20f2018-02-27 15:56:11 -080054 DISALLOW_COPY_AND_ASSIGN(CacheLocation);
55
56 // When there isn't enough room on the target filesystem to hold the patched version of the file,
57 // we copy the original here and delete it to free up space. If the expected source file doesn't
58 // exist, or is corrupted, we look to see if the cached file contains the bits we want and use it
59 // as the source instead. The default location for the cached source is "/cache/saved.file".
60 std::string cache_temp_source_;
61
62 // Location to save the last command that stashes blocks.
63 std::string last_command_file_;
64
65 // The base directory to write stashes during update.
66 std::string stash_directory_base_;
67};
68
69#endif // _OTAUTIL_OTAUTIL_CACHE_LOCATION_H_