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

Side by Side Diff: src/DefaultFileSystem.cpp

Issue 10369004: File system path resolving (Closed)
Patch Set: Addressing comments Created May 5, 2013, 10:49 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 | « include/AdblockPlus/FileSystem.h ('k') | test/BaseJsTest.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 #include <AdblockPlus/DefaultFileSystem.h> 1 #include <AdblockPlus/DefaultFileSystem.h>
2 #include <cstdio> 2 #include <cstdio>
3 #include <cstring> 3 #include <cstring>
4 #include <fstream> 4 #include <fstream>
5 #include <stdexcept> 5 #include <stdexcept>
6 6
7 #include <cerrno> 7 #include <cerrno>
8 #include <sys/types.h> 8 #include <sys/types.h>
9 #include <sys/stat.h> 9 #include <sys/stat.h>
10 10
11 #ifdef _WIN32 11 #ifdef _WIN32
12 #ifndef S_ISDIR 12 #ifndef S_ISDIR
13 #define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) 13 #define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
14 #include <Shlobj.h> 14 #include <Shlobj.h>
15 #include <Shlwapi.h>
15 #endif 16 #endif
16 17
17 #ifndef S_ISREG 18 #ifndef S_ISREG
18 #define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG) 19 #define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
19 #endif 20 #endif
20 #endif 21 #endif
21 22
22 #include "../src/Utils.h" 23 #include "../src/Utils.h"
23 24
24 using namespace AdblockPlus; 25 using namespace AdblockPlus;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 FileSystem::StatResult result; 85 FileSystem::StatResult result;
85 result.exists = true; 86 result.exists = true;
86 result.isFile = S_ISREG(nativeStat.st_mode); 87 result.isFile = S_ISREG(nativeStat.st_mode);
87 result.isDirectory = S_ISDIR(nativeStat.st_mode); 88 result.isDirectory = S_ISDIR(nativeStat.st_mode);
88 result.lastModified = static_cast<int64_t>(nativeStat.st_mtime) * 1000; 89 result.lastModified = static_cast<int64_t>(nativeStat.st_mtime) * 1000;
89 return result; 90 return result;
90 } 91 }
91 92
92 std::string DefaultFileSystem::Resolve(const std::string& path) const 93 std::string DefaultFileSystem::Resolve(const std::string& path) const
93 { 94 {
94 return basePath + "\\" + path; 95 if (basePath == "")
96 {
97 return path;
98 }
99 else
100 {
101 if (PathIsRelative(Utils::ToUTF16String(path, path.length()).c_str()))
Wladimir Palant 2013/05/06 06:18:30 This is Windows-specific and won't compile on othe
Wladimir Palant 2013/05/06 06:19:51 Oops, exactly the other way round of course: i
102 {
103 return basePath + PATH_SEPARATOR + path;
104 }
105 else
106 {
107 return path;
108 }
109 }
95 } 110 }
96 111
97 void DefaultFileSystem::SetBasePath(const std::string& path) 112 void DefaultFileSystem::SetBasePath(const std::string& path)
98 { 113 {
114 basePath = path;
99 115
100 if (path.rfind('\\') == (path.length() - 1)) 116 if ((*basePath.rbegin() == PATH_SEPARATOR))
Wladimir Palant 2013/05/06 06:18:30 Nit: You seem to have an extra pair parentheses he
101 { 117 {
102 basePath = path.substr(0, path.length() - 1); 118 basePath.pop_back();
103 }
104 else
105 {
106 basePath = path;
107 } 119 }
108 } 120 }
109 121
OLDNEW
« no previous file with comments | « include/AdblockPlus/FileSystem.h ('k') | test/BaseJsTest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld