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
{
13 DMGIterator::DMGIterator(ReadStream
* stream
)
16 current_partition_(0),
20 DMGIterator::~DMGIterator() {}
22 bool DMGIterator::Open() {
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_
) {
42 hfs_
.reset(new HFSIterator(partitions_
[current_partition_
]));
47 // Iterate through the HFS filesystem until a concrete file is found.
52 // Skip directories and symlinks.
53 if (hfs_
->IsDirectory() || hfs_
->IsSymbolicLink())
56 // Hard links are not supported by the HFSIterator.
57 if (hfs_
->IsHardLink())
60 // Decmpfs compression is not supported by the HFSIterator.
61 if (hfs_
->IsDecmpfsCompressed())
64 // This must be a normal file!
74 base::string16
DMGIterator::GetPath() {
75 return hfs_
->GetPath();
78 scoped_ptr
<ReadStream
> DMGIterator::GetReadStream() {
79 return hfs_
->GetReadStream();
83 } // namespace safe_browsing