File tree Expand file tree Collapse file tree 4 files changed +77
-0
lines changed Expand file tree Collapse file tree 4 files changed +77
-0
lines changed Original file line number Diff line number Diff line change 1+ %% PYTHON.IS_MOUNT is path a mount point
2+ %
3+ % https://docs.python.org/3/library/os.path.html#os.path.ismount
4+
5+ function y = is_mount(filepath )
6+
7+ try
8+ y = py .os .path .ismount(filepath );
9+ catch e
10+ warning(e .identifier , " Python is_mount failed: %s" , e .message );
11+ y = false ;
12+ end
13+
14+ end
Original file line number Diff line number Diff line change 1+ function y = is_mount(filepath )
2+
3+
4+ if ispc()
5+ if any(ismember(filepath , [" /" , " \" ])) || ...
6+ (endsWith(filepath , [" /" , " \" ]) && isfolder(filepath ) && filepath == stdlib .root(filepath ))
7+ y = true ;
8+ return
9+ end
10+ cmd = strcat(' pwsh -c "(Get-Item -Path '' ' , filepath , ' '' ).Attributes.ToString().Contains('' ReparsePoint'' )"' );
11+ elseif ismac()
12+ cmd = " [ $(stat -f %d " + filepath + " ) != $(stat -f %d " + stdlib .parent(filepath ) + " )]" ;
13+ else
14+ cmd = " mountpoint -q " + filepath ;
15+ end
16+
17+ [s , m ] = system(cmd );
18+
19+ if ispc()
20+ y = s == 0 && m == " True" ;
21+ else
22+ y = s == 0 ;
23+ end
24+
25+
26+ end
Original file line number Diff line number Diff line change 1+ %% IS_MOUNT is filepath a mount path
2+ %
3+ % Examples:
4+ %
5+ % * Windows: is_mount("c:") false; is_mount("C:\") true
6+ % * Linux, macOS, Windows: is_mount("/") true
7+
8+ function y = is_mount(filepath , method )
9+ arguments
10+ filepath {mustBeTextScalar }
11+ method (1 ,: ) string = [" python" , " sys" ]
12+ end
13+
14+ fun = choose_method(method , " is_mount" );
15+ y = fun(filepath );
16+
17+ end
Original file line number Diff line number Diff line change 1414hl_fun = {' java' , ' python' }
1515fst_fun = {' sys' , ' dotnet' , ' java' , ' python' }
1616is_remove = {' dotnet' , ' sys' }
17+ py_sys = {' python' , ' sys' }
1718end
1819
1920methods (TestClassSetup )
@@ -55,6 +56,25 @@ function test_is_removable(tc, is_remove)
5556end
5657
5758
59+ function test_is_mount(tc , py_sys )
60+ try
61+ y = stdlib .is_mount(pwd(), py_sys );
62+ catch e
63+ tc .verifyEqual(e .identifier , ' stdlib:choose_method:NameError' , e .message )
64+ return
65+ end
66+
67+ tc .verifyClass(y , ' logical' )
68+ tc .verifyTrue(stdlib .is_mount(" /" , py_sys ))
69+
70+ if ispc()
71+ tc .verifyFalse(stdlib .is_mount(getenv(" SystemDrive" ), py_sys ))
72+ tc .verifyTrue(stdlib .is_mount(getenv(" SystemDrive" ) + " /" , py_sys ))
73+ tc .verifyTrue(stdlib .is_mount(getenv(" SystemDrive" ) + " \" , py_sys ))
74+ end
75+ end
76+
77+
5878function test_hard_link_count(tc , hl_fun )
5979fname = " hard_link_count" ;
6080n = " stdlib." + hl_fun + " ." + fname ;
You can’t perform that action at this time.
0 commit comments