7
7
# Note: os.path is used instead of pathlib because certain functionality such as
8
8
# os.path.normpath() lack a pathlib equivalent.
9
9
10
+ def resolve_filename (opts , name : str ) -> str :
11
+ if opts .symlink_mode :
12
+ if opts .symlink_mode == "L" :
13
+ # resolve instances of ".." first
14
+ name = os .path .normpath (name )
15
+
16
+ name = os .path .realpath (name , strict = opts .can_mode == "e" )
17
+
18
+ if not opts .can_mode :
19
+ # raise an error if directory missing
20
+ os .path .realpath (os .path .dirname (name ), strict = True )
21
+ else :
22
+ if opts .can_mode == "e" :
23
+ # raise an error if missing
24
+ os .path .realpath (name , strict = True )
25
+
26
+ name = os .path .abspath (name )
27
+
28
+ return name
10
29
11
30
def realpath (opts , filenames : list [str ]):
12
31
endchar = "\0 " if opts .zero else "\n "
@@ -18,22 +37,7 @@ def realpath(opts, filenames: list[str]):
18
37
19
38
for name in filenames :
20
39
try :
21
- if not opts .symlink_mode :
22
- if opts .can_mode == "e" :
23
- # raise an error if missing
24
- os .path .realpath (name , strict = True )
25
-
26
- name = os .path .abspath (name )
27
- else :
28
- if opts .symlink_mode == "L" :
29
- # resolve instances of ".." first
30
- name = os .path .normpath (name )
31
-
32
- name = os .path .realpath (name , strict = opts .can_mode == "e" )
33
-
34
- if not opts .can_mode :
35
- # raise an error if directory missing
36
- os .path .realpath (os .path .dirname (name ), strict = True )
40
+ name = resolve_filename (opts , name )
37
41
except OSError as e :
38
42
failed = True
39
43
0 commit comments