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

Side by Side Diff: src/DefaultFileSystem.cpp

Issue 29533641: Issue 5569 - add the possibility to use synchronous WebRequest and base path in File System (Closed) Base URL: https://github.com/adblockplus/libadblockplus.git
Patch Set: Created Sept. 1, 2017, 3:32 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/DefaultFileSystem.h ('k') | src/DefaultWebRequest.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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-present eyeo GmbH 3 * Copyright (C) 2006-present 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 #else 61 #else
62 // POSIX systems: assume that file system encoding is UTF-8 and just use the 62 // POSIX systems: assume that file system encoding is UTF-8 and just use the
63 // file paths as they are. 63 // file paths as they are.
64 std::string NormalizePath(const std::string& path) 64 std::string NormalizePath(const std::string& path)
65 { 65 {
66 return path; 66 return path;
67 } 67 }
68 #endif 68 #endif
69 } 69 }
70 70
71 DefaultFileSystemSync::DefaultFileSystemSync(const std::string& path)
72 : basePath(path)
73 {
74 if (!basePath.empty() && *basePath.rbegin() == PATH_SEPARATOR)
75 {
76 basePath.resize(basePath.size() - 1);
77 }
78 }
79
71 IFileSystem::IOBuffer 80 IFileSystem::IOBuffer
72 DefaultFileSystemSync::Read(const std::string& path) const 81 DefaultFileSystemSync::Read(const std::string& path) const
73 { 82 {
74 std::ifstream file(NormalizePath(path).c_str(), std::ios_base::binary); 83 std::ifstream file(NormalizePath(path).c_str(), std::ios_base::binary);
75 if (file.fail()) 84 if (file.fail())
76 throw RuntimeErrorWithErrno("Failed to open " + path); 85 throw RuntimeErrorWithErrno("Failed to open " + path);
77 86
78 file.seekg(0, std::ios_base::end); 87 file.seekg(0, std::ios_base::end);
79 auto dataSize = file.tellg(); 88 auto dataSize = file.tellg();
80 file.seekg(0, std::ios_base::beg); 89 file.seekg(0, std::ios_base::beg);
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 { 185 {
177 return basePath + PATH_SEPARATOR + path; 186 return basePath + PATH_SEPARATOR + path;
178 } 187 }
179 else 188 else
180 { 189 {
181 return path; 190 return path;
182 } 191 }
183 } 192 }
184 } 193 }
185 194
186 void DefaultFileSystemSync::SetBasePath(const std::string& path)
187 {
188 basePath = path;
189
190 if (*basePath.rbegin() == PATH_SEPARATOR)
191 {
192 basePath.resize(basePath.size() - 1);
193 }
194 }
195
196 DefaultFileSystem::DefaultFileSystem(const Scheduler& scheduler, std::unique_ptr <DefaultFileSystemSync> syncImpl) 195 DefaultFileSystem::DefaultFileSystem(const Scheduler& scheduler, std::unique_ptr <DefaultFileSystemSync> syncImpl)
197 : scheduler(scheduler), syncImpl(std::move(syncImpl)) 196 : scheduler(scheduler), syncImpl(std::move(syncImpl))
198 { 197 {
199 } 198 }
200 199
201 void DefaultFileSystem::Read(const std::string& fileName, 200 void DefaultFileSystem::Read(const std::string& fileName,
202 const ReadCallback& callback) const 201 const ReadCallback& callback) const
203 { 202 {
204 scheduler([this, fileName, callback] 203 scheduler([this, fileName, callback]
205 { 204 {
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 error = "Unknown error while calling stat on " + fileName + " as " + Resol ve(fileName); 310 error = "Unknown error while calling stat on " + fileName + " as " + Resol ve(fileName);
312 } 311 }
313 callback(StatResult(), error); 312 callback(StatResult(), error);
314 }); 313 });
315 } 314 }
316 315
317 std::string DefaultFileSystem::Resolve(const std::string& fileName) const 316 std::string DefaultFileSystem::Resolve(const std::string& fileName) const
318 { 317 {
319 return syncImpl->Resolve(fileName); 318 return syncImpl->Resolve(fileName);
320 } 319 }
OLDNEW
« no previous file with comments | « src/DefaultFileSystem.h ('k') | src/DefaultWebRequest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld