vrclient: Improve relative path handling in vrclient_dos_to_unix_path().

CW-Bug-Id: #24798
This commit is contained in:
Paul Gofman 2025-01-29 15:27:50 -06:00
parent 7b0ae2e1d1
commit 0417c5dd8d

View File

@ -55,8 +55,10 @@ static char *get_unix_file_name( const WCHAR *path )
char *vrclient_dos_to_unix_path( const char *src ) char *vrclient_dos_to_unix_path( const char *src )
{ {
WCHAR srcW[PATH_MAX] = {'\\', '?', '?', '\\', 0}, *tmp;
char buffer[4096], *dst = buffer; char buffer[4096], *dst = buffer;
uint32_t len; char *unix_path;
uint32_t len, r;
TRACE( "src %s\n", debugstr_a(src) ); TRACE( "src %s\n", debugstr_a(src) );
@ -65,50 +67,39 @@ char *vrclient_dos_to_unix_path( const char *src )
*dst = 0; *dst = 0;
if (!*src) goto done; if (!*src) goto done;
if (IS_ABSOLUTE( src )) len = 4;
if (!IS_ABSOLUTE( src ))
{ {
/* absolute path, use wine conversion */ CURDIR *curdir = &NtCurrentTeb()->Peb->ProcessParameters->CurrentDirectory;
WCHAR srcW[PATH_MAX] = {'\\', '?', '?', '\\', 0}, *tmp;
char *unix_path;
uint32_t r;
r = ntdll_umbstowcs( src, strlen( src ) + 1, srcW + 4, PATH_MAX - 4 ); memcpy( srcW + len, curdir->DosPath.Buffer, curdir->DosPath.Length );
if (r == 0) unix_path = NULL; len += curdir->DosPath.Length / 2;
else TRACE("relative, srcW %s.\n", debugstr_w(srcW));
{
for (tmp = srcW; *tmp; ++tmp) if (*tmp == '/') *tmp = '\\';
unix_path = get_unix_file_name( srcW );
}
if (!unix_path)
{
WARN( "Unable to convert DOS filename to unix: %s\n", src );
return NULL;
}
if (!realpath( unix_path, dst ))
{
ERR( "Could not get real path for %s.\n", unix_path );
lstrcpynA( dst, unix_path, PATH_MAX );
}
free( unix_path );
} }
r = ntdll_umbstowcs( src, strlen( src ) + 1, srcW + len, PATH_MAX - len );
if (r == 0) unix_path = NULL;
else else
{ {
/* relative path, just fix up backslashes */ for (tmp = srcW; *tmp; ++tmp) if (*tmp == '/') *tmp = '\\';
const char *s; unix_path = get_unix_file_name( srcW );
char *d;
for (s = src, d = dst; *src; ++s, ++d)
{
if (*s == '\\') *d = '/';
else *d = *s;
}
*d = 0;
} }
if (!unix_path)
{
WARN( "Unable to convert DOS filename to unix: %s\n", src );
return NULL;
}
if (!realpath( unix_path, dst ))
{
ERR( "Could not get real path for %s.\n", unix_path );
lstrcpynA( dst, unix_path, PATH_MAX );
}
free( unix_path );
done: done:
len = strlen( buffer ) + 1; len = strlen( buffer ) + 1;
if (!(dst = (char *)malloc( len ))) return NULL; if (!(dst = (char *)malloc( len ))) return NULL;