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

Side by Side Diff: src/DefaultFileSystem.cpp

Issue 29538640: Issue 5610 - Deal with a '/' base path (Closed) Base URL: https://hg.adblockplus.org/libadblockplus/
Patch Set: Created Sept. 7, 2017, 4:31 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 | « no previous file | test/DefaultFileSystem.cpp » ('j') | test/DefaultFileSystem.cpp » ('J')
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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
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) 71 DefaultFileSystemSync::DefaultFileSystemSync(const std::string& path)
72 : basePath(path) 72 : basePath(path)
73 { 73 {
74 if (!basePath.empty() && *basePath.rbegin() == PATH_SEPARATOR) 74 if (basePath.size() > 1 && *basePath.rbegin() == PATH_SEPARATOR)
75 { 75 {
76 basePath.resize(basePath.size() - 1); 76 basePath.resize(basePath.size() - 1);
77 } 77 }
78 } 78 }
79 79
80 IFileSystem::IOBuffer 80 IFileSystem::IOBuffer
81 DefaultFileSystemSync::Read(const std::string& path) const 81 DefaultFileSystemSync::Read(const std::string& path) const
82 { 82 {
83 std::ifstream file(NormalizePath(path).c_str(), std::ios_base::binary); 83 std::ifstream file(NormalizePath(path).c_str(), std::ios_base::binary);
84 if (file.fail()) 84 if (file.fail())
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 return path; 176 return path;
177 } 177 }
178 else 178 else
179 { 179 {
180 #ifdef _WIN32 180 #ifdef _WIN32
181 if (PathIsRelative(NormalizePath(path).c_str())) 181 if (PathIsRelative(NormalizePath(path).c_str()))
182 #else 182 #else
183 if (path.length() && *path.begin() != PATH_SEPARATOR) 183 if (path.length() && *path.begin() != PATH_SEPARATOR)
184 #endif 184 #endif
185 { 185 {
186 return basePath + PATH_SEPARATOR + path; 186 if (*basePath.rbegin() != PATH_SEPARATOR)
187 return basePath + PATH_SEPARATOR + path;
188 else
189 return basePath + path;
187 } 190 }
188 else 191 else
189 { 192 {
190 return path; 193 return path;
191 } 194 }
192 } 195 }
193 } 196 }
194 197
195 DefaultFileSystem::DefaultFileSystem(const Scheduler& scheduler, std::unique_ptr <DefaultFileSystemSync> syncImpl) 198 DefaultFileSystem::DefaultFileSystem(const Scheduler& scheduler, std::unique_ptr <DefaultFileSystemSync> syncImpl)
196 : scheduler(scheduler), syncImpl(std::move(syncImpl)) 199 : scheduler(scheduler), syncImpl(std::move(syncImpl))
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 error = "Unknown error while calling stat on " + fileName + " as " + Resol ve(fileName); 313 error = "Unknown error while calling stat on " + fileName + " as " + Resol ve(fileName);
311 } 314 }
312 callback(StatResult(), error); 315 callback(StatResult(), error);
313 }); 316 });
314 } 317 }
315 318
316 std::string DefaultFileSystem::Resolve(const std::string& fileName) const 319 std::string DefaultFileSystem::Resolve(const std::string& fileName) const
317 { 320 {
318 return syncImpl->Resolve(fileName); 321 return syncImpl->Resolve(fileName);
319 } 322 }
OLDNEW
« no previous file with comments | « no previous file | test/DefaultFileSystem.cpp » ('j') | test/DefaultFileSystem.cpp » ('J')

Powered by Google App Engine
This is Rietveld