LEFT | RIGHT |
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-2017 eyeo GmbH | 3 * Copyright (C) 2006-2017 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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 std::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::shared_ptr<std::istream> result(new std::ifstream(NormalizePath(path).c_s
tr())); | 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 const std::shared_ptr<std::istream>& data) | 79 std::istream& data) |
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); |
90 } | 90 } |
91 | 91 |
92 void DefaultFileSystem::Remove(const std::string& path) | 92 void DefaultFileSystem::Remove(const std::string& path) |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 |
LEFT | RIGHT |