| OLD | NEW | 
|---|
| 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 187 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 198 void DefaultFileSystemSync::SetBasePath(const std::string& path) | 198 void DefaultFileSystemSync::SetBasePath(const std::string& path) | 
| 199 { | 199 { | 
| 200   basePath = path; | 200   basePath = path; | 
| 201 | 201 | 
| 202   if (*basePath.rbegin() == PATH_SEPARATOR) | 202   if (*basePath.rbegin() == PATH_SEPARATOR) | 
| 203   { | 203   { | 
| 204     basePath.resize(basePath.size() - 1); | 204     basePath.resize(basePath.size() - 1); | 
| 205   } | 205   } | 
| 206 } | 206 } | 
| 207 | 207 | 
| 208 DefaultFileSystem::DefaultFileSystem(std::unique_ptr<DefaultFileSystemSync> sync
     Impl) | 208 DefaultFileSystem::DefaultFileSystem(const Scheduler& scheduler, std::unique_ptr
     <DefaultFileSystemSync> syncImpl) | 
| 209   : syncImpl(std::move(syncImpl)) | 209   : scheduler(scheduler), syncImpl(std::move(syncImpl)) | 
| 210 { | 210 { | 
| 211 } | 211 } | 
| 212 | 212 | 
| 213 void DefaultFileSystem::Read(const std::string& path, | 213 void DefaultFileSystem::Read(const std::string& path, | 
| 214                              const ReadCallback& callback) const | 214                              const ReadCallback& callback) const | 
| 215 { | 215 { | 
| 216   std::thread([this, path, callback] | 216   scheduler([this, path, callback] | 
| 217   { | 217   { | 
| 218     std::string error; | 218     std::string error; | 
| 219     try | 219     try | 
| 220     { | 220     { | 
| 221       auto data = syncImpl->Read(path); | 221       auto data = syncImpl->Read(path); | 
| 222       callback(std::move(data), error); | 222       callback(std::move(data), error); | 
| 223       return; | 223       return; | 
| 224     } | 224     } | 
| 225     catch (std::exception& e) | 225     catch (std::exception& e) | 
| 226     { | 226     { | 
| 227       error = e.what(); | 227       error = e.what(); | 
| 228     } | 228     } | 
| 229     catch (...) | 229     catch (...) | 
| 230     { | 230     { | 
| 231       error =  "Unknown error while reading from " + path; | 231       error =  "Unknown error while reading from " + path; | 
| 232     } | 232     } | 
| 233     callback(IOBuffer(), error); | 233     callback(IOBuffer(), error); | 
| 234   }).detach(); | 234   }); | 
| 235 } | 235 } | 
| 236 | 236 | 
| 237 void DefaultFileSystem::Write(const std::string& path, | 237 void DefaultFileSystem::Write(const std::string& path, | 
| 238                               const IOBuffer& data, | 238                               const IOBuffer& data, | 
| 239                               const Callback& callback) | 239                               const Callback& callback) | 
| 240 { | 240 { | 
| 241   std::thread([this, path, data, callback] | 241   scheduler([this, path, data, callback] | 
| 242   { | 242   { | 
| 243     std::string error; | 243     std::string error; | 
| 244     try | 244     try | 
| 245     { | 245     { | 
| 246       syncImpl->Write(path, data); | 246       syncImpl->Write(path, data); | 
| 247     } | 247     } | 
| 248     catch (std::exception& e) | 248     catch (std::exception& e) | 
| 249     { | 249     { | 
| 250       error = e.what(); | 250       error = e.what(); | 
| 251     } | 251     } | 
| 252     catch (...) | 252     catch (...) | 
| 253     { | 253     { | 
| 254       error = "Unknown error while writing to " + path; | 254       error = "Unknown error while writing to " + path; | 
| 255     } | 255     } | 
| 256     callback(error); | 256     callback(error); | 
| 257   }).detach(); | 257   }); | 
| 258 } | 258 } | 
| 259 | 259 | 
| 260 void DefaultFileSystem::Move(const std::string& fromPath, | 260 void DefaultFileSystem::Move(const std::string& fromPath, | 
| 261                              const std::string& toPath, | 261                              const std::string& toPath, | 
| 262                              const Callback& callback) | 262                              const Callback& callback) | 
| 263 { | 263 { | 
| 264   std::thread([this, fromPath, toPath, callback] | 264   scheduler([this, fromPath, toPath, callback] | 
| 265   { | 265   { | 
| 266     std::string error; | 266     std::string error; | 
| 267     try | 267     try | 
| 268     { | 268     { | 
| 269       syncImpl->Move(fromPath, toPath); | 269       syncImpl->Move(fromPath, toPath); | 
| 270     } | 270     } | 
| 271     catch (std::exception& e) | 271     catch (std::exception& e) | 
| 272     { | 272     { | 
| 273       error = e.what(); | 273       error = e.what(); | 
| 274     } | 274     } | 
| 275     catch (...) | 275     catch (...) | 
| 276     { | 276     { | 
| 277       error = "Unknown error while moving " + fromPath + " to " + toPath; | 277       error = "Unknown error while moving " + fromPath + " to " + toPath; | 
| 278     } | 278     } | 
| 279     callback(error); | 279     callback(error); | 
| 280   }).detach(); | 280   }); | 
| 281 } | 281 } | 
| 282 | 282 | 
| 283 void DefaultFileSystem::Remove(const std::string& path, | 283 void DefaultFileSystem::Remove(const std::string& path, | 
| 284                                const Callback& callback) | 284                                const Callback& callback) | 
| 285 { | 285 { | 
| 286   std::thread([this, path, callback] | 286   scheduler([this, path, callback] | 
| 287   { | 287   { | 
| 288     std::string error; | 288     std::string error; | 
| 289     try | 289     try | 
| 290     { | 290     { | 
| 291       syncImpl->Remove(path); | 291       syncImpl->Remove(path); | 
| 292     } | 292     } | 
| 293     catch (std::exception& e) | 293     catch (std::exception& e) | 
| 294     { | 294     { | 
| 295       error = e.what(); | 295       error = e.what(); | 
| 296     } | 296     } | 
| 297     catch (...) | 297     catch (...) | 
| 298     { | 298     { | 
| 299       error = "Unknown error while removing " + path; | 299       error = "Unknown error while removing " + path; | 
| 300     } | 300     } | 
| 301     callback(error); | 301     callback(error); | 
| 302   }).detach(); | 302   }); | 
| 303 } | 303 } | 
| 304 | 304 | 
| 305 void DefaultFileSystem::Stat(const std::string& path, | 305 void DefaultFileSystem::Stat(const std::string& path, | 
| 306                              const StatCallback& callback) const | 306                              const StatCallback& callback) const | 
| 307 { | 307 { | 
| 308   std::thread([this, path, callback] | 308   scheduler([this, path, callback] | 
| 309   { | 309   { | 
| 310     std::string error; | 310     std::string error; | 
| 311     try | 311     try | 
| 312     { | 312     { | 
| 313       auto result = syncImpl->Stat(path); | 313       auto result = syncImpl->Stat(path); | 
| 314       callback(result, error); | 314       callback(result, error); | 
| 315       return; | 315       return; | 
| 316     } | 316     } | 
| 317     catch (std::exception& e) | 317     catch (std::exception& e) | 
| 318     { | 318     { | 
| 319       error = e.what(); | 319       error = e.what(); | 
| 320     } | 320     } | 
| 321     catch (...) | 321     catch (...) | 
| 322     { | 322     { | 
| 323       error = "Unknown error while calling stat on " + path; | 323       error = "Unknown error while calling stat on " + path; | 
| 324     } | 324     } | 
| 325     callback(StatResult(), error); | 325     callback(StatResult(), error); | 
| 326   }).detach(); | 326   }); | 
| 327 } | 327 } | 
| 328 | 328 | 
| 329 std::string DefaultFileSystem::Resolve(const std::string& path) const | 329 std::string DefaultFileSystem::Resolve(const std::string& path) const | 
| 330 { | 330 { | 
| 331   return syncImpl->Resolve(path); | 331   return syncImpl->Resolve(path); | 
| 332 } | 332 } | 
| OLD | NEW | 
|---|