Skip to content

Commit fb6d7ef

Browse files
committed
[windows] more win path stuff
1 parent 18de702 commit fb6d7ef

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

src/base/fs_util.cc

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,21 @@
4848
#include "pcrepp/pcre2pp.hh"
4949
#include "scn/scan.h"
5050
#include "short_alloc.h"
51+
#include "string_util.hh"
5152

5253
#ifdef HAVE_LIBPROC_H
5354
# include <libproc.h>
5455
#endif
5556

5657
namespace lnav::filesystem {
5758

59+
static bool have_cygdrive()
60+
{
61+
static const auto RETVAL = access("/cygdrive", X_OK) == 0;
62+
63+
return RETVAL;
64+
}
65+
5866
std::string
5967
escape_glob_for_win(std::string arg)
6068
{
@@ -237,6 +245,9 @@ path_transcoder::from(std::string arg)
237245
}
238246

239247
arg.insert(arg.begin(), '/');
248+
if (have_cygdrive()) {
249+
arg.insert(0, "/cygdrive");
250+
}
240251
std::replace(arg.begin(), arg.end(), '\\', '/');
241252

242253
return {arg, caps};
@@ -249,7 +260,15 @@ path_transcoder::to_native(std::string arg)
249260
return arg;
250261
}
251262

252-
arg.erase(0, 1);
263+
static const auto CYGDRIVE = "/cygdrive"_frag;
264+
265+
if (startswith(arg, CYGDRIVE.data())) {
266+
arg.erase(0, CYGDRIVE.length());
267+
}
268+
269+
if (arg[0] == '/') {
270+
arg.erase(0, 1);
271+
}
253272
if (this->pt_root_name_capitalized.value()) {
254273
arg[0] = toupper(arg[0]);
255274
}

0 commit comments

Comments
 (0)