OLD | NEW |
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_SPLIT_FILE_WRITER_H__ | 5 #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_SPLIT_FILE_WRITER_H__ |
6 #define CHROMEOS_PLATFORM_UPDATE_ENGINE_SPLIT_FILE_WRITER_H__ | 6 #define CHROMEOS_PLATFORM_UPDATE_ENGINE_SPLIT_FILE_WRITER_H__ |
7 | 7 |
8 #include "update_engine/file_writer.h" | 8 #include "update_engine/file_writer.h" |
9 | 9 |
10 // SplitFileWriter is an implementation of FileWriter suited to our | 10 // SplitFileWriter is an implementation of FileWriter suited to our |
11 // full autoupdate format. The first 8 bytes read are assumed to be a | 11 // full autoupdate format. The first 8 bytes read are assumed to be a |
12 // big-endian number describing how many of the next following bytes | 12 // big-endian number describing how many of the next following bytes |
13 // go to the first FileWriter. After that, the rest of the bytes all | 13 // go to the first FileWriter. After that, the rest of the bytes all |
14 // go to the second FileWriter. | 14 // go to the second FileWriter. |
15 | 15 |
16 namespace chromeos_update_engine { | 16 namespace chromeos_update_engine { |
17 | 17 |
18 class SplitFileWriter : public FileWriter { | 18 class SplitFileWriter : public FileWriter { |
19 public: | 19 public: |
20 SplitFileWriter(FileWriter* first_file_writer, FileWriter* second_file_writer) | 20 SplitFileWriter(FileWriter* first_file_writer, FileWriter* second_file_writer) |
21 : first_file_writer_(first_file_writer), | 21 : first_file_writer_(first_file_writer), |
22 first_length_(0), | 22 first_length_(0), |
23 first_path_(NULL), | 23 first_path_(NULL), |
24 first_flags_(0), | 24 first_flags_(0), |
25 first_mode_(0), | 25 first_mode_(0), |
26 second_file_writer_(second_file_writer), | 26 second_file_writer_(second_file_writer), |
27 bytes_received_(0) {} | 27 bytes_received_(0) {} |
28 | 28 |
29 void SetFirstOpenArgs(const char* path, int flags, mode_t mode) { | 29 void SetFirstOpenArgs(const char* path, int flags, mode_t mode) { |
30 first_path_ = path; | 30 first_path_ = path; |
31 first_flags_ = flags; | 31 first_flags_ = flags; |
32 first_mode_ = mode; | 32 first_mode_ = mode; |
33 } | 33 } |
34 | 34 |
35 // If both succeed, returns the return value from the second Open() call. | 35 // If both succeed, returns the return value from the second Open() call. |
36 // On error, both files will be left closed. | 36 // On error, both files will be left closed. |
37 virtual int Open(const char* path, int flags, mode_t mode); | 37 virtual int Open(const char* path, int flags, mode_t mode); |
38 | 38 |
39 virtual ssize_t Write(const void* bytes, size_t count); | 39 virtual ssize_t Write(const void* bytes, size_t count); |
40 | 40 |
41 virtual int Close(); | 41 virtual int Close(); |
42 | 42 |
43 private: | 43 private: |
44 // Data for the first file writer. | 44 // Data for the first file writer. |
45 FileWriter* const first_file_writer_; | 45 FileWriter* const first_file_writer_; |
46 off_t first_length_; | 46 off_t first_length_; |
47 const char* first_path_; | 47 const char* first_path_; |
48 int first_flags_; | 48 int first_flags_; |
49 mode_t first_mode_; | 49 mode_t first_mode_; |
50 | 50 |
51 // The scond file writeer. | 51 // The second file writer. |
52 FileWriter* const second_file_writer_; | 52 FileWriter* const second_file_writer_; |
53 | 53 |
54 // Bytes written thus far | 54 // Bytes written thus far. |
55 off_t bytes_received_; | 55 off_t bytes_received_; |
56 char first_length_buf_[sizeof(uint64_t)]; | 56 char first_length_buf_[sizeof(uint64_t)]; |
57 | 57 |
58 DISALLOW_COPY_AND_ASSIGN(SplitFileWriter); | 58 DISALLOW_COPY_AND_ASSIGN(SplitFileWriter); |
59 }; | 59 }; |
60 | 60 |
61 } // namespace chromeos_update_engine | 61 } // namespace chromeos_update_engine |
62 | 62 |
63 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_SPLIT_FILE_WRITER_H__ | 63 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_SPLIT_FILE_WRITER_H__ |
OLD | NEW |