Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Crashpad Authors. All rights reserved. | |
| 2 // | |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
| 4 // you may not use this file except in compliance with the License. | |
| 5 // You may obtain a copy of the License at | |
| 6 // | |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | |
| 8 // | |
| 9 // Unless required by applicable law or agreed to in writing, software | |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 12 // See the License for the specific language governing permissions and | |
| 13 // limitations under the License. | |
| 14 | |
| 15 #include "util/test/scoped_temp_dir.h" | |
| 16 | |
| 17 #include <dirent.h> | |
| 18 #include <string.h> | |
| 19 #include <unistd.h> | |
| 20 | |
| 21 #include "base/logging.h" | |
| 22 #include "gtest/gtest.h" | |
| 23 #include "util/test/errors.h" | |
| 24 | |
| 25 namespace crashpad { | |
| 26 namespace test { | |
| 27 | |
| 28 // static | |
| 29 base::FilePath ScopedTempDir::CreateTemporaryDirectory() { | |
| 30 char dir_tempalate[] = "/tmp/com.googlecode.crashpad.test.XXXXXX"; | |
| 31 PCHECK(mkdtemp(dir_tempalate)) << "mkdtemp " << dir_tempalate; | |
| 32 return base::FilePath(dir_tempalate); | |
| 33 } | |
| 34 | |
| 35 // static | |
| 36 void ScopedTempDir::RecursivelyDeleteTemporaryDirectory( | |
| 37 const base::FilePath& path) { | |
| 38 DIR* dir = opendir(path.value().c_str()); | |
| 39 ASSERT_TRUE(dir) << ErrnoMessage("opendir") << " " << path.value(); | |
| 40 | |
| 41 dirent* entry; | |
| 42 while ((entry = readdir(dir))) { | |
| 43 if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) { | |
| 44 continue; | |
| 45 } | |
| 46 | |
| 47 base::FilePath entry_path = path.Append(entry->d_name); | |
| 48 if (entry->d_type == DT_DIR) { | |
| 49 RecursivelyDeleteTemporaryDirectory(entry_path); | |
| 50 } else { | |
| 51 EXPECT_EQ(0, unlink(entry_path.value().c_str())) << ErrnoMessage("unlink") | |
|
Mark Mentovai
2015/01/02 17:49:54
Put everything from << to the ; onto its own conti
Robert Sesek
2015/01/02 18:51:13
Done.
| |
| 52 << " " | |
| 53 << entry_path.value(); | |
| 54 } | |
| 55 } | |
| 56 | |
| 57 EXPECT_EQ(0, closedir(dir)) | |
| 58 << ErrnoMessage("closedir") << " " << path.value(); | |
| 59 EXPECT_EQ(0, rmdir(path.value().c_str())) | |
| 60 << ErrnoMessage("rmdir") << " " << path.value(); | |
| 61 } | |
| 62 | |
| 63 } // namespace test | |
| 64 } // namespace crashpad | |
| OLD | NEW |