MCPcopy Create free account
hub / github.com/Pagghiu/SaneCppLibraries / convert

Method convert

Libraries/FileSystem/FileSystem.cpp:154–209  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

152 return changeDirectory(currentWorkingDirectory);
153}
154
155SC::ResultFileSystem SC::FileSystem::changeDirectory(StringSpan currentWorkingDirectory)
156{
157#if SC_PLATFORM_WINDOWS
158 const auto pathResult = FileSystemWindowsDetail::WindowsPath::makeAbsoluteLogicalPath(
159 currentWorkingDirectory, currentDirectory.view(), currentDirectory);
160 if (not pathResult)
161 return translateWindowsPathError(pathResult, FileSystemErrorDetail::NormalizePath);
162#else
163 if (not currentDirectory.assign(currentWorkingDirectory))
164 return {FileSystemError::PathCapacityExceeded, FileSystemErrorDetail::ChangeDirectory};
165#endif
166 bool isDirectory;
167 SC_TRY(existsAndIsDirectory(".", isDirectory));
168 if (not isDirectory)
169 return {FileSystemError::EntryNotFound, FileSystemErrorDetail::ChangeDirectory};
170 return Result(true);
171}
172
173SC::ResultFileSystem SC::FileSystem::convert(const StringSpan file, StringPath& destination,
174 StringNativeBuffer<StringPath::MaxPath + 6 + 1>& transportPath,
175 StringSpan* encodedPath)
176{
177#if SC_PLATFORM_WINDOWS
178 if (currentDirectory.view().isEmpty())
179 {
180 const auto logicalPathResult = FileSystemWindowsDetail::WindowsPath::makeLogicalPath(file, destination);
181 if (not logicalPathResult)
182 return translateWindowsPathError(logicalPathResult, FileSystemErrorDetail::NormalizePath);
183 if (not FileSystemWindowsDetail::WindowsPath::isAbsolute(destination.view()))
184 return {FileSystemError::NotInitialized, FileSystemErrorDetail::BuildTransportPath};
185 }
186 const auto pathResult = FileSystemWindowsDetail::WindowsPath::makeTransportPath(file, currentDirectory.view(),
187 destination, transportPath);
188 if (not pathResult)
189 return translateWindowsPathError(pathResult, FileSystemErrorDetail::BuildTransportPath);
190 if (encodedPath != nullptr)
191 {
192 *encodedPath = transportPath.view();
193 }
194 return Result(true);
195#else
196 (void)(transportPath);
197 if (not destination.assign(file))
198 return {FileSystemError::PathCapacityExceeded, FileSystemErrorDetail::BuildTransportPath};
199 if (encodedPath)
200 {
201 *encodedPath = destination.view();
202 }
203
204 auto destinationBuffer = destination.writableSpan().data();
205 const bool absolute = not destination.view().isEmpty() and destinationBuffer[0] == '/';
206 if (absolute)
207 {
208 if (encodedPath != nullptr)
209 {
210 *encodedPath = destination.view();
211 }

Callers

nothing calls this directly

Calls 8

writableSpanMethod · 0.80
ResultClass · 0.50
viewMethod · 0.45
assignMethod · 0.45
dataMethod · 0.45
isEmptyMethod · 0.45
sizeInBytesMethod · 0.45
resizeMethod · 0.45

Tested by

no test coverage detected