Update CrOS OOBE throbber to MD throbber; delete old asset
[chromium-blink-merge.git] / chrome / utility / safe_browsing / mac / dmg_iterator.cc
blob270bef76ccdb8788ea27e69315b8fbb80b88e385
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/utility/safe_browsing/mac/dmg_iterator.h"
7 #include "chrome/utility/safe_browsing/mac/hfs.h"
8 #include "chrome/utility/safe_browsing/mac/read_stream.h"
10 namespace safe_browsing {
11 namespace dmg {
13 DMGIterator::DMGIterator(ReadStream* stream)
14 : udif_(stream),
15 partitions_(),
16 current_partition_(0),
17 hfs_() {
20 DMGIterator::~DMGIterator() {}
22 bool DMGIterator::Open() {
23 if (!udif_.Parse())
24 return false;
26 // Collect all the HFS partitions up-front. The data are accessed lazily, so
27 // this is relatively inexpensive.
28 for (size_t i = 0; i < udif_.GetNumberOfPartitions(); ++i) {
29 if (udif_.GetPartitionType(i) == "Apple_HFS" ||
30 udif_.GetPartitionType(i) == "Apple_HFSX") {
31 partitions_.push_back(udif_.GetPartitionReadStream(i).Pass());
35 return partitions_.size() > 0;
38 bool DMGIterator::Next() {
39 // Iterate through all the HFS partitions in the DMG file.
40 for (; current_partition_ < partitions_.size(); ++current_partition_) {
41 if (!hfs_) {
42 hfs_.reset(new HFSIterator(partitions_[current_partition_]));
43 if (!hfs_->Open())
44 continue;
47 // Iterate through the HFS filesystem until a concrete file is found.
48 while (true) {
49 if (!hfs_->Next())
50 break;
52 // Skip directories and symlinks.
53 if (hfs_->IsDirectory() || hfs_->IsSymbolicLink())
54 continue;
56 // Hard links are not supported by the HFSIterator.
57 if (hfs_->IsHardLink())
58 continue;
60 // Decmpfs compression is not supported by the HFSIterator.
61 if (hfs_->IsDecmpfsCompressed())
62 continue;
64 // This must be a normal file!
65 return true;
68 hfs_.reset();
71 return false;
74 base::string16 DMGIterator::GetPath() {
75 return hfs_->GetPath();
78 scoped_ptr<ReadStream> DMGIterator::GetReadStream() {
79 return hfs_->GetReadStream();
82 } // namespace dmg
83 } // namespace safe_browsing