File tree Expand file tree Collapse file tree 7 files changed +35
-22
lines changed Expand file tree Collapse file tree 7 files changed +35
-22
lines changed Original file line number Diff line number Diff line change 1010 p {mustBeTextScalar ,mustBeFile }
1111end
1212
13+ s = [];
14+
1315if stdlib .isoctave()
14- s = stat(p );
15- if ~isempty( s )
16- s = s .size ;
16+ [ st , err ] = stat(p );
17+ if err == 0
18+ s = st .size ;
1719 end
1820else
19- s = dir(p );
20- if ~isempty(s )
21- s = s .bytes ;
21+ d = dir(p );
22+ if ~isempty(d )
23+ s = d .bytes ;
2224 end
2325end
2426
Original file line number Diff line number Diff line change 1313
1414
1515if stdlib .isoctave()
16- s = stat(p );
17- if isempty(s )
18- t = [];
19- else
16+ [s , err ] = stat(p );
17+ if err == 0
2018 t = s .mtime ;
19+ else
20+ t = [];
2121 end
2222 return
2323end
Original file line number Diff line number Diff line change 1515 switch e .identifier
1616 case " MATLAB:io:filesystem:filePermissions:CannotFindLocation" , return
1717 case " Octave:undefined-function"
18- try % #ok<TRYNC>
19- p = stat(f ).modestr;
18+ [s , err ] = stat(f );
19+ if err == 0
20+ p = s .modestr ;
2021 end
2122 return
2223 case " MATLAB:UndefinedFunction"
Original file line number Diff line number Diff line change 1313c = [];
1414
1515if stdlib .isoctave()
16- s = stat(p );
17- if ~isempty( s )
16+ [ s , err ] = stat(p );
17+ if err == 0
1818 c = s .nlink ;
1919 end
2020elseif ispc() || ~isfile(p )
Original file line number Diff line number Diff line change 1010end
1111
1212if stdlib .isoctave()
13- ok = S_ISCHR(stat(p ).mode);
13+ [s , err ] = stat(p );
14+ ok = err == 0 && S_ISCHR(s .mode );
1415else
1516 error(" buildtool mex" )
1617end
Original file line number Diff line number Diff line change 1212catch e
1313 switch e .identifier
1414 case " MATLAB:UndefinedFunction" , ok = java .nio .file .Files .isSymbolicLink(javaPathObject(stdlib .absolute(p )));
15- case " Octave:undefined-function" , ok = S_ISLNK(stat(p ).mode);
15+ case " Octave:undefined-function"
16+ [s , err ] = stat(p );
17+ ok = err == 0 && S_ISLNK(s .mode );
1618 otherwise , rethrow(e )
1719 end
1820end
Original file line number Diff line number Diff line change 99%
1010% %% Inputs
1111% * path1, path2: paths to compare
12- % %% Outputs
13- % issame: logical
1412
15-
16- function issame = samepath(path1 , path2 )
13+ function y = samepath(path1 , path2 )
1714arguments
1815 path1 {mustBeTextScalar }
1916 path2 {mustBeTextScalar }
2219% simpler our way than
2320% https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/nio/file/Files.html#isSameFile(java.nio.file.Path,java.nio.file.Path)
2421
25- issame = stdlib .exists(path1 ) && stdlib .exists(path2 ) && ...
26- strcmp(stdlib .canonical(path1 ), stdlib .canonical(path2 ));
22+ y = stdlib .exists(path1 ) && stdlib .exists(path2 );
23+
24+ if ~y , return ; end
25+
26+ if ~ispc() && stdlib .isoctave()
27+ [r1 , e1 ] = stat(path1 );
28+ [r2 , e2 ] = stat(path2 );
29+
30+ y = e1 == 0 && e2 == 0 && ...
31+ r1.ino == r2 .ino && r1 .dev == r2 .dev ;
2732
33+ else
34+ y = strcmp(stdlib .canonical(path1 ), stdlib .canonical(path2 ));
2835end
2936
3037% !assert(samepath(".", "."))
You can’t perform that action at this time.
0 commit comments