Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(352)

Side by Side Diff: util/test/scoped_temp_dir_posix.cc

Issue 834693002: Create ScopedTempDir, implement it on POSIX, and use it where appropriate. (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 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 <unistd.h>
19
20 #include "base/logging.h"
21 #include "gtest/gtest.h"
22 #include "util/test/errors.h"
23
24 namespace crashpad {
25 namespace test {
26
27 base::FilePath ScopedTempDir::CreateTemporaryDirectory() {
28 char dir_tempalate[] = "/tmp/com.googlecode.crashpad.temp_dir.XXXXXX";
Mark Mentovai 2014/12/31 05:51:09 Test-specific things so far have used com.googleco
Robert Sesek 2015/01/02 17:34:08 Done.
29 CHECK(mkdtemp(dir_tempalate)) << ErrnoMessage("mkdtemp");
Mark Mentovai 2014/12/31 05:51:09 Also: add << " " << dir_template?
Mark Mentovai 2014/12/31 05:51:09 PCHECK(), not CHECK(). Then you can lose the Errno
Robert Sesek 2015/01/02 17:34:08 Done.
Robert Sesek 2015/01/02 17:34:09 Done.
30 return base::FilePath(dir_tempalate);
31 }
32
33 void ScopedTempDir::RecursivelyDeleteTemporaryDirectory(
34 const base::FilePath& path) {
Mark Mentovai 2014/12/31 05:51:09 dir_path might further disambiguate from entry_pat
35 DIR* dir = opendir(path.value().c_str());
Mark Mentovai 2014/12/31 05:51:10 You ought to be able to make a scoper for this out
Robert Sesek 2015/01/02 17:34:09 I tried this, but it's more code and I don't think
36 ASSERT_TRUE(dir) << ErrnoMessage("opendir") << " " << path.value();
37
38 struct dirent* entry;
Mark Mentovai 2014/12/31 05:51:10 Can you just call this dirent* without the struct
Robert Sesek 2015/01/02 17:34:08 Done, though my preference is to keep "struct" whe
39 while ((entry = readdir(dir))) {
40 base::FilePath entry_path = path.Append(entry->d_name);
Mark Mentovai 2014/12/31 05:51:09 No point in doing this until after you’ve checked
Robert Sesek 2015/01/02 17:34:09 Done.
41 if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) {
Mark Mentovai 2014/12/31 05:51:09 #include <string.h>.
Robert Sesek 2015/01/02 17:34:08 Done.
42 continue;
43 }
44
45 if (entry->d_type == DT_DIR) {
46 RecursivelyDeleteTemporaryDirectory(entry_path);
Mark Mentovai 2014/12/31 06:07:28 You should set entry to nullptr to affirmatively s
Mark Mentovai 2015/01/01 06:40:20 I wrote:
47 } else {
48 EXPECT_EQ(0, unlink(entry_path.value().c_str())) << ErrnoMessage("unlink")
Mark Mentovai 2014/12/31 05:51:09 The message would be easier to read if you put the
Robert Sesek 2015/01/02 17:34:08 Done.
49 << " "
50 << entry_path.value();
51 }
52 }
53
54 EXPECT_EQ(0, closedir(dir)) << ErrnoMessage("closedir") << " "
55 << path.value();
56 EXPECT_EQ(0, rmdir(path.value().c_str())) << ErrnoMessage("rmdir")
57 << " " << path.value();
58 }
59
60 } // namespace test
61 } // namespace crashpad
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698