Home | History | Annotate | Download | only in otautil
      1 /*
      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.
     26 class CacheLocation {
     27  public:
     28   static CacheLocation& location();
     29 
     30   // 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:
     53   CacheLocation();
     54   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_
     70