• Home
  • Raw
  • Download

Lines Matching +full:path +full:- +full:is +full:- +full:absolute

10 # This software is licensed as described in the file COPYING, which
15 # copies of the Software, and permit persons to whom the Software is
18 # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21 # SPDX-License-Identifier: curl
25 # This Perl package helps with path transforming when running curl tests on
30 # (1) /some/path - absolute path in Unix-style
31 # (2) D:/some/path - absolute path in Win32-style
32 # (3) some/path - relative path
33 # (4) D:some/path - path relative to current directory on Win32 drive (paths
35 # (5) \some/path - path from root directory on current Win32 drive (*)
44 # On non-Windows platforms functions acts as transparent wrappers for similar
50 # control on Win32 current drive and Win32 current path on specific drive.
78 # Cached static variable, Perl 5.0-compatible.
83 # Returns boolean true if OS is any form of Windows.
88 # Cached static variable, Perl 5.0-compatible.
94 $cygdrive_present = ((-e '/cygdrive/') && (-d '/cygdrive/')) ? 1 : 0;
100 # undef - autodetect
101 # 0 - do not use cygpath
102 # 1 - use cygpath
104 # Returns boolean true if 'cygpath' utility should be used for path conversion.
108 $use_cygpath = (qx{cygpath -u '.\\' 2>/dev/null} eq "./\n" && $? == 0);
116 # Performs path "normalization": all slashes converted to forward
120 # Path processed as string, directories are not checked for presence so
121 # path for not yet existing directory can be "normalized".
133 # MSys shell has built-in command.
134 chomp($cur_dir = `bash -c 'pwd -W'`);
143 # Do not use 'cygpath' - it falsely succeed on paths like '/cygdrive'.
162 # Notice parameter "/c;" - it's required to turn off Msys's
173 # Internal function. Converts path by using Msys's built-in transformation.
174 # Returned path may contain duplicated and back slashes.
178 # drive letter ('c'), second optional parameter is path relative to drive's
179 # current working directory. Returns Win32 absolute normalized path.
183 # absolute Unix-style path. Other types of paths are not supported.
190 # Converts given path to system native format, i.e. to Win32 format on
191 # Windows platform. Relative paths converted to relative, absolute
192 # paths converted to absolute.
195 my ($path) = @_;
197 # Return untouched on non-Windows platforms.
198 return $path if (!os_is_win());
200 # Do not process empty path.
201 return $path if ($path eq '');
203 if($path =~ s{^([a-zA-Z]):$}{\u$1:}) {
204 # Path is single drive with colon. (C:)
205 # This type of paths is not processed correctly by 'cygpath'.
207 # Be careful, this relative path can be accidentally transformed
208 # into wrong absolute path by adding to it some '/dirname' with
210 return $path;
212 elsif($path =~ m{^\\} || $path =~ m{^[a-zA-Z]:[^/\\]}) {
213 # Path is a directory or filename on Win32 current drive or relative
214 # path on current directory on specific Win32 drive.
215 # ('\path' or 'D:path')
216 # First type of paths is not processed by Msys transformation and
217 # resolved to absolute path by 'cygpath'.
218 # Second type is not processed by Msys transformation and may be
221 my $first_char = ucfirst(substr($path, 0, 1));
224 $path =~ s{[\\/]+}{/}g;
228 substr($path, 0, 1, $first_char);
229 return $path;
232 # 'cygpath' is available - use it.
236 $path =~ s{^([\\/])[\\/]+}{$1}g;
238 my $has_final_slash = ($path =~ m{[/\\]$});
240 # Use 'cygpath', '-m' means Win32 path with forward slashes.
241 chomp($path = `cygpath -m '$path'`);
243 warn "Can't convert path by \"cygpath\".\n";
248 $path .= '/' if($has_final_slash);
252 $path =~ s{//+}{/}g;
254 return $path;
257 # Msys transforms automatically path to Windows native form in staring
258 # program parameters if program is not Msys-based.
260 $path = do_msys_transform($path);
261 return undef if !defined $path;
264 $path =~ s{^([a-z]:)}{\u$1};
267 $path =~ s{[\\/]+}{/}g;
268 return $path;
270 elsif($path =~ s{^([a-zA-Z]):[/\\]}{\u$1:/}) {
271 # Path is already in Win32 form. ('C:\path')
274 $path =~ s{[\\/]+}{/}g;
275 return $path;
277 elsif($path !~ m{^/}) {
278 # Path is in relative form. ('path/name', './path' or '../path')
281 $path =~ s{[\\/]+}{/}g;
282 return $path;
285 # OS is Windows, but not Msys, path is absolute, path is not in Win32
286 # form and 'cygpath' is not available.
287 return do_dumb_guessed_transform($path);
291 # Converts given path to system native absolute path, i.e. to Win32
292 # absolute format on Windows platform. Both relative and absolute
296 my ($path) = @_;
299 # Convert path to absolute form.
300 $path = Cwd::abs_path($path);
302 # Do not process further on non-Windows platforms.
303 return $path;
306 if($path =~ m{^([a-zA-Z]):($|[^/\\].*$)}) {
307 # Path is single drive with colon or relative path on Win32 drive.
308 # ('C:' or 'C:path')
309 # This kind of relative path is not processed correctly by 'cygpath'.
313 elsif($path eq '') {
314 # Path is empty string. Return current directory.
320 # 'cygpath' is available - use it.
322 my $has_final_slash = ($path =~ m{[\\/]$});
326 $path =~ s{^([\\/])[\\/]+}{$1}g;
328 print "Inter result: \"$path\"\n";
329 # Use 'cygpath', '-m' means Win32 path with forward slashes,
330 # '-a' means absolute path
331 chomp($path = `cygpath -m -a '$path'`);
333 warn "Can't resolve path by usung \"cygpath\".\n";
338 $path .= '/' if($has_final_slash);
342 $path =~ s{//+}{/}g;
344 return $path
346 elsif($path =~ s{^([a-zA-Z]):[/\\]}{\u$1:/}) {
347 # Path is already in Win32 form. ('C:\path')
351 return normalize_path($path);
353 elsif(substr($path, 0, 1) eq '\\' ) {
354 # Path is directory or filename on Win32 current drive. ('\Windows')
359 # Combine drive and path.
362 return normalize_path($w32drive . $path);
365 if(substr($path, 0, 1) ne '/') {
366 # Path is in relative form. Resolve relative directories in Unix form
371 # MSys shell has built-in command.
373 $cur_dir = `bash -c 'pwd -L'`;
376 $cur_dir = `pwd -L`;
384 $path = $cur_dir . '/' . $path;
388 $path = normalize_path($path);
389 return undef unless defined $path;
392 # Msys transforms automatically path to Windows native form in staring
393 # program parameters if program is not Msys-based.
394 $path = do_msys_transform($path);
395 return undef if !defined $path;
398 $path =~ s{[\\/]+}{/}g;
399 return $path;
401 # OS is Windows, but not Msys, path is absolute, path is not in Win32
402 # form and 'cygpath' is not available.
404 return do_dumb_guessed_transform($path);
407 # Internal function. Converts given Unix-style absolute path to Win32 format.
411 # Converts given path to build system format absolute path, i.e. to
412 # Msys/Cygwin Unix-style absolute format on Windows platform. Both
413 # relative and absolute formats are supported for input.
416 my ($path) = @_;
419 # Convert path to absolute form.
420 $path = Cwd::abs_path($path);
422 # Do not process further on non-Windows platforms.
423 return $path;
426 if($path =~ m{^([a-zA-Z]):($|[^/\\].*$)}) {
427 # Path is single drive with colon or relative path on Win32 drive.
428 # ('C:' or 'C:path')
429 # This kind of relative path is not processed correctly by 'cygpath'.
432 # Resolve relative dirs in Win32-style path or paths like 'D:/../c/'
436 $path = get_abs_path_on_win32_drive($1, $2);
437 return undef if !defined $path;
439 return simple_transform_win32_to_unix($path);
441 elsif($path eq '') {
442 # Path is empty string. Return current directory.
445 # MSys shell has built-in command.
447 chomp($path = `bash -c 'pwd -L'`);
450 chomp($path = `pwd -L`);
453 warn "Can't determine Unix-style current working directory.\n";
458 $path .= '/' if length($path) > 2;
459 return $path;
462 # 'cygpath' is available - use it.
464 my $has_final_slash = ($path =~ m{[\\/]$});
467 # Unix-style paths.
469 $path = normalize_path($path);
470 return undef if !defined $path;
472 # Use 'cygpath', '-u' means Unix-stile path,
473 # '-a' means absolute path
474 chomp($path = `cygpath -u -a '$path'`);
476 warn "Can't resolve path by usung \"cygpath\".\n";
480 # 'cygpath' removes last slash if path is root dir on Win32 drive.
482 $path .= '/' if($has_final_slash &&
483 substr($path, length($path) - 1, 1) ne '/');
485 return $path
487 elsif($path =~ m{^[a-zA-Z]:[/\\]}) {
488 # Path is already in Win32 form. ('C:\path')
490 # Resolve relative dirs in Win32-style path otherwise paths
494 $path = normalize_path($path);
495 return undef if !defined $path;
497 return simple_transform_win32_to_unix($path);
499 elsif(substr($path, 0, 1) eq '\\') {
500 # Path is directory or filename on Win32 current drive. ('\Windows')
505 # Combine drive and path.
506 # Resolve relative dirs in Win32-style path or paths like 'D:/../c/'
510 $path = normalize_path($w32drive . $path);
511 return undef if !defined $path;
513 return simple_transform_win32_to_unix($path);
516 # Path is not in any Win32 form.
517 if(substr($path, 0, 1) ne '/') {
518 # Path in relative form. Resolve relative directories in Unix form
523 # MSys shell has built-in command.
525 $cur_dir = `bash -c 'pwd -L'`;
528 $cur_dir = `pwd -L`;
536 $path = $cur_dir . '/' . $path;
539 return normalize_path($path);
543 # Performs path "normalization": all slashes converted to forward
547 # Path processed as string, directories are not checked for presence so
548 # path for not yet existing directory can be "normalized".
551 my ($path) = @_;
554 return $path if $path eq '';
556 if($path !~ m{(?:^|\\|/)\.{1,2}(?:\\|/|$)}) {
558 my $first_char = substr($path, 0, 1);
559 $path =~ s{[\\/]+}{/}g;
561 substr($path, 0, 1, $first_char);
562 return $path;
569 # Check whether path starts from Win32 drive. ('C:path' or 'C:\path')
570 if($path =~ m{^([a-zA-Z]:(/|\\)?)(.*$)}) {
573 # Process path separately from drive letter.
579 if($path =~ m{^(\/|\\)}) {
586 @arr = split(m{\/|\\}, $path);
596 elsif($el eq '..' && @res > 0 && $res[-1] ne '..') {
603 warn "Error processing path \"$path\": " .
609 $ret .= '/' if($path =~ m{\\$|/$} && scalar @res > 0);
614 # Internal function. Converts path by using Msys's built-in
617 my ($path) = @_;
619 return $path if $path eq '';
623 $path =~ s{^/[/\\]+}{/};
625 # Msys transforms automatically path to Windows native form in staring
626 # program parameters if program is not Msys-based.
627 # Note: already checked that $path is non-empty.
628 $path = `cmd //c echo '$path'`;
630 warn "Can't transform path into Win32 form by using Msys" .
637 $path =~ s{^\"|\"$|\"\r|\n|\r}{}g;
639 return $path;
643 # drive letter ('c'), second optional parameter is path relative to drive's
644 # current working directory. Returns Win32 absolute normalized path.
650 # "/c;" is compatible with both Msys and Cygwin.
658 # Current directory on drive is not set, default is
668 # Append relative path part.
679 # absolute Unix-style path. Other types of paths are not supported.
684 my ($path) = @_;
688 $path =~ s{[/\\]+}{/}g;
690 # Empty path is not valid.
691 return undef if (length($path) == 0);
695 qr{^/cygdrive/([a-zA-Z])($|/.*$)} :
696 qr{^/([a-zA-Z])($|/.*$)};
698 # Check path whether path is Win32 directly mapped drive and try to
699 # transform it assuming that drive letter is matched to Win32 drive letter.
700 if($path =~ m{$drv_ltr_re}) {
705 # This may be some custom mapped path. ('/mymount/path')
707 # Must check longest possible path component as subdir can be mapped to
710 my $check_path = $path;
713 if(-d $check_path) {
716 if($? == 0 && substr($path, 0, 1) ne '%') {
739 warn "Can't determine Win32 directory for path \"$path\".\n";
746 # Internal function. Converts given Unix-style absolute path to Win32 format.
748 my ($path) = @_;
753 chomp($res = `cygpath -a -u '$path'`);
755 warn "Can't determine Unix-style directory for Win32 " .
756 "directory \"$path\".\n";
760 # 'cygpath' removes last slash if path is root dir on Win32 drive.
761 $res .= '/' if(substr($res, length($res) - 1, 1) ne '/' &&
762 $path =~ m{[/\\]$});
766 # 'cygpath' is not available, use guessed transformation.
767 if($path !~ s{^([a-zA-Z]):(?:/|\\)}{/\l$1/}) {
768 warn "Can't determine Unix-style directory for Win32 " .
769 "directory \"$path\".\n";
773 $path = '/cygdrive' . $path if(drives_mounted_on_cygdrive());
774 return $path;