• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 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.
4 
5 #include "mojo/tools/package_manager/unpacker.h"
6 
7 #include "base/files/file_util.h"
8 #include "base/logging.h"
9 #include "third_party/zlib/google/zip.h"
10 
11 namespace mojo {
12 
Unpacker()13 Unpacker::Unpacker() {
14 }
15 
~Unpacker()16 Unpacker::~Unpacker() {
17   if (!dir_.empty())
18     DeleteFile(dir_, true);
19 }
20 
Unpack(const base::FilePath & zip_file)21 bool Unpacker::Unpack(const base::FilePath& zip_file) {
22   DCHECK(zip_file_.empty());
23   zip_file_ = zip_file;
24 
25   DCHECK(dir_.empty());
26   if (!CreateNewTempDirectory(base::FilePath::StringType(), &dir_))
27     return false;
28   if (!zip::Unzip(zip_file, dir_)) {
29     dir_ = base::FilePath();
30     return false;
31   }
32   return true;
33 }
34 
35 }  // namespace mojo
36