Chromium Code Reviews| 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 #include "update_engine/delta_diff_generator.h" | 5 #include "update_engine/delta_diff_generator.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <fcntl.h> | 8 #include <fcntl.h> |
| 9 #include <inttypes.h> | 9 #include <inttypes.h> |
| 10 #include <sys/stat.h> | 10 #include <sys/stat.h> |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 134 // For each regular file within new_root, creates a node in the graph, | 134 // For each regular file within new_root, creates a node in the graph, |
| 135 // determines the best way to compress it (REPLACE, REPLACE_BZ, COPY, BSDIFF), | 135 // determines the best way to compress it (REPLACE, REPLACE_BZ, COPY, BSDIFF), |
| 136 // and writes any necessary data to the end of data_fd. | 136 // and writes any necessary data to the end of data_fd. |
| 137 bool DeltaReadFiles(Graph* graph, | 137 bool DeltaReadFiles(Graph* graph, |
| 138 vector<Block>* blocks, | 138 vector<Block>* blocks, |
| 139 const string& old_root, | 139 const string& old_root, |
| 140 const string& new_root, | 140 const string& new_root, |
| 141 int data_fd, | 141 int data_fd, |
| 142 off_t* data_file_size) { | 142 off_t* data_file_size) { |
| 143 set<ino_t> visited_inodes; | 143 set<ino_t> visited_inodes; |
| 144 set<ino_t> visited_src_inodes; | |
| 144 for (FilesystemIterator fs_iter(new_root, | 145 for (FilesystemIterator fs_iter(new_root, |
| 145 utils::SetWithValue<string>("/lost+found")); | 146 utils::SetWithValue<string>("/lost+found")); |
| 146 !fs_iter.IsEnd(); fs_iter.Increment()) { | 147 !fs_iter.IsEnd(); fs_iter.Increment()) { |
| 147 if (!S_ISREG(fs_iter.GetStat().st_mode)) | 148 if (!S_ISREG(fs_iter.GetStat().st_mode)) |
| 148 continue; | 149 continue; |
| 149 | 150 |
| 150 // Make sure we visit each inode only once. | 151 // Make sure we visit each inode only once. |
| 151 if (utils::SetContainsKey(visited_inodes, fs_iter.GetStat().st_ino)) | 152 if (utils::SetContainsKey(visited_inodes, fs_iter.GetStat().st_ino)) |
| 152 continue; | 153 continue; |
| 153 visited_inodes.insert(fs_iter.GetStat().st_ino); | 154 visited_inodes.insert(fs_iter.GetStat().st_ino); |
| 154 if (fs_iter.GetStat().st_size == 0) | 155 if (fs_iter.GetStat().st_size == 0) |
| 155 continue; | 156 continue; |
| 156 | 157 |
| 157 LOG(INFO) << "Encoding file " << fs_iter.GetPartialPath(); | 158 LOG(INFO) << "Encoding file " << fs_iter.GetPartialPath(); |
| 158 | 159 |
| 160 bool should_diff_from_source = true; | |
| 161 string src_path = old_root + fs_iter.GetPartialPath(); | |
| 162 if (utils::FileExists(src_path.c_str())) { | |
| 163 struct stat src_stbuf; | |
| 164 TEST_AND_RETURN_FALSE_ERRNO(0 == stat(src_path.c_str(), &src_stbuf)); | |
| 165 should_diff_from_source = !utils::SetContainsKey(visited_src_inodes, | |
|
petkov
2011/02/15 06:01:38
Add a comment what this is trying to catch and wha
| |
| 166 src_stbuf.st_ino); | |
| 167 visited_src_inodes.insert(src_stbuf.st_ino); | |
| 168 } | |
| 169 | |
| 159 TEST_AND_RETURN_FALSE(DeltaReadFile(graph, | 170 TEST_AND_RETURN_FALSE(DeltaReadFile(graph, |
| 160 Vertex::kInvalidIndex, | 171 Vertex::kInvalidIndex, |
| 161 blocks, | 172 blocks, |
| 162 old_root, | 173 (should_diff_from_source ? |
| 174 old_root : | |
| 175 "/-!@:&*nonexistent_path"), | |
|
petkov
2011/02/15 06:01:38
This feels a bit of a hack. Maybe use an empty str
| |
| 163 new_root, | 176 new_root, |
| 164 fs_iter.GetPartialPath(), | 177 fs_iter.GetPartialPath(), |
| 165 data_fd, | 178 data_fd, |
| 166 data_file_size)); | 179 data_file_size)); |
| 167 } | 180 } |
| 168 return true; | 181 return true; |
| 169 } | 182 } |
| 170 | 183 |
| 171 // This class allocates non-existent temp blocks, starting from | 184 // This class allocates non-existent temp blocks, starting from |
| 172 // kTempBlockStart. Other code is responsible for converting these | 185 // kTempBlockStart. Other code is responsible for converting these |
| (...skipping 1428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1601 dummy_extent->set_start_block(kSparseHole); | 1614 dummy_extent->set_start_block(kSparseHole); |
| 1602 dummy_extent->set_num_blocks((signature_blob_length + kBlockSize - 1) / | 1615 dummy_extent->set_num_blocks((signature_blob_length + kBlockSize - 1) / |
| 1603 kBlockSize); | 1616 kBlockSize); |
| 1604 } | 1617 } |
| 1605 | 1618 |
| 1606 const char* const kBsdiffPath = "bsdiff"; | 1619 const char* const kBsdiffPath = "bsdiff"; |
| 1607 const char* const kBspatchPath = "bspatch"; | 1620 const char* const kBspatchPath = "bspatch"; |
| 1608 const char* const kDeltaMagic = "CrAU"; | 1621 const char* const kDeltaMagic = "CrAU"; |
| 1609 | 1622 |
| 1610 }; // namespace chromeos_update_engine | 1623 }; // namespace chromeos_update_engine |
| OLD | NEW |