Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: src/DefaultFileSystem.cpp

Issue 5163715573841920: Issue 768 - Switch from TR1 to C++11 (Closed)
Patch Set: rebase Created Aug. 5, 2015, 10:38 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 #else 59 #else
60 // POSIX systems: assume that file system encoding is UTF-8 and just use the 60 // POSIX systems: assume that file system encoding is UTF-8 and just use the
61 // file paths as they are. 61 // file paths as they are.
62 std::string NormalizePath(const std::string& path) 62 std::string NormalizePath(const std::string& path)
63 { 63 {
64 return path; 64 return path;
65 } 65 }
66 #endif 66 #endif
67 } 67 }
68 68
69 std::tr1::shared_ptr<std::istream> 69 std::shared_ptr<std::istream>
70 DefaultFileSystem::Read(const std::string& path) const 70 DefaultFileSystem::Read(const std::string& path) const
71 { 71 {
72 std::tr1::shared_ptr<std::istream> result(new std::ifstream(NormalizePath(path ).c_str())); 72 std::shared_ptr<std::istream> result(new std::ifstream(NormalizePath(path).c_s tr()));
73 if (result->fail()) 73 if (result->fail())
74 throw RuntimeErrorWithErrno("Failed to open " + path); 74 throw RuntimeErrorWithErrno("Failed to open " + path);
75 return result; 75 return result;
76 } 76 }
77 77
78 void DefaultFileSystem::Write(const std::string& path, 78 void DefaultFileSystem::Write(const std::string& path,
79 std::tr1::shared_ptr<std::istream> data) 79 std::shared_ptr<std::istream> data)
Felix Dahlke 2015/08/05 21:28:04 Nit: This was wrapped because it didn't fit in 80
Wladimir Palant 2015/08/06 12:24:54 Sergei didn't reply for some reason but this won't
Felix Dahlke 2015/08/06 18:19:01 True, my bad.
80 { 80 {
81 std::ofstream file(NormalizePath(path).c_str(), std::ios_base::out | std::ios_ base::binary); 81 std::ofstream file(NormalizePath(path).c_str(), std::ios_base::out | std::ios_ base::binary);
82 file << Utils::Slurp(*data); 82 file << Utils::Slurp(*data);
83 } 83 }
84 84
85 void DefaultFileSystem::Move(const std::string& fromPath, 85 void DefaultFileSystem::Move(const std::string& fromPath,
86 const std::string& toPath) 86 const std::string& toPath)
87 { 87 {
88 if (rename(NormalizePath(fromPath).c_str(), NormalizePath(toPath).c_str())) 88 if (rename(NormalizePath(fromPath).c_str(), NormalizePath(toPath).c_str()))
89 throw RuntimeErrorWithErrno("Failed to move " + fromPath + " to " + toPath); 89 throw RuntimeErrorWithErrno("Failed to move " + fromPath + " to " + toPath);
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 void DefaultFileSystem::SetBasePath(const std::string& path) 187 void DefaultFileSystem::SetBasePath(const std::string& path)
188 { 188 {
189 basePath = path; 189 basePath = path;
190 190
191 if (*basePath.rbegin() == PATH_SEPARATOR) 191 if (*basePath.rbegin() == PATH_SEPARATOR)
192 { 192 {
193 basePath.resize(basePath.size() - 1); 193 basePath.resize(basePath.size() - 1);
194 } 194 }
195 } 195 }
196 196
OLDNEW

Powered by Google App Engine
This is Rietveld