File tree Expand file tree Collapse file tree 6 files changed +43
-43
lines changed Expand file tree Collapse file tree 6 files changed +43
-43
lines changed Original file line number Diff line number Diff line change 11function i = device(file )
2- arguments
3- file (1 ,1 ) string
4- end
52
63i = uint64([]);
7- if ~stdlib .exists(file ), return , end
84
9- opt = java .nio .file .LinkOption .values();
5+ if stdlib .strempty(file )
6+ return
7+ end
108
11- jp = javaPathObject(stdlib .absolute(file ));
129% Java 1.8 benefits from the absolute() for stability
1310% seen on older Matlab versions on HPC
11+ opt = java .nio .file .LinkOption .values();
1412
15- try % #ok<TRYNC>
16- i = java .nio .file .Files .getAttribute(jp , ' unix:dev' , opt );
13+ try
14+ i = java .nio .file .Files .getAttribute(javaAbsolutePath(file ), " unix:dev" , opt );
15+ catch e
16+ if class(e .ExceptionObject ) ~= " java.nio.file.NoSuchFileException"
17+ rethrow(e )
18+ end
1719end
1820
1921i = uint64(i );
Original file line number Diff line number Diff line change 77% this try-catch is faster and more robust
88
99function n = get_owner(file )
10- arguments
11- file (1 ,1 ) string
12- end
1310
1411% https://docs.oracle.com/en/java/javase/22/docs/api/java.base/java/nio/file/Files.html#getOwner(java.nio.file.Path,java.nio.file.LinkOption...)
1512% https://docs.oracle.com/en/java/javase/22/docs/api/java.base/java/nio/file/LinkOption.html
Original file line number Diff line number Diff line change 1- function c = hard_link_count(file )
2- arguments
3- file (1 ,1 ) string
4- end
1+ function i = hard_link_count(file )
52
63opt = java .nio .file .LinkOption .values();
74try
8- c = java .nio .file .Files .getAttribute(javaPathObject(file ), " unix:nlink" , opt );
9- catch
10- c = [];
5+ i = java .nio .file .Files .getAttribute(javaAbsolutePath(file ), " unix:nlink" , opt );
6+ catch e
7+ if class(e .ExceptionObject ) ~= " java.nio.file.NoSuchFileException"
8+ rethrow(e )
9+ end
10+ i = [];
1111end
1212end
Original file line number Diff line number Diff line change 11function i = inode(file )
2- arguments
3- file (1 ,1 ) string
4- end
52
63i = uint64([]);
7- if ~stdlib .exists(file ), return , end
84
9- opt = java .nio .file .LinkOption .values();
5+ if stdlib .strempty(file )
6+ return
7+ end
108
11- jp = javaPathObject( stdlib . absolute(file ));
12- % Java 1.8 benefits from the absolute() for stability--it's not an issue
13- % on every computer.
9+ % Java 1.8 benefits from the absolute() for stability
10+ % seen on older Matlab versions on HPC
11+ opt = java . nio . file . LinkOption .values();
1412
15- try % #ok<TRYNC>
16- i = java .nio .file .Files .getAttribute(jp , " unix:ino" , opt );
13+ try
14+ i = java .nio .file .Files .getAttribute(javaAbsolutePath(file ), " unix:ino" , opt );
15+ catch e
16+ if class(e .ExceptionObject ) ~= " java.nio.file.NoSuchFileException"
17+ rethrow(e )
18+ end
1719end
1820
1921i = uint64(i );
Original file line number Diff line number Diff line change 1+ function javaPath = javaAbsolutePath(file )
2+ % java.lang.System.getProperty('user.path') is stuck to where Java started
3+
4+ if ischar(file ) || isstring(file )
5+ file = java .io .File(file );
6+ end
7+ javaPath = file .toPath();
8+
9+ if ~javaPath .isAbsolute()
10+ javaPath = javaPathObject(pwd()).resolve(javaPath );
11+ end
12+
13+ end
Original file line number Diff line number Diff line change 66f2 = java .io .File(path2 );
77
88if f1 .exists() && f2 .exists()
9- p1 = file2absPath(f1 );
10- p2 = file2absPath(f2 );
11- y = java .nio .file .Files .isSameFile(p1 , p2 );
9+ y = java .nio .file .Files .isSameFile(javaAbsolutePath(f1 ), javaAbsolutePath(f2 ));
1210else
1311 y = false ;
1412end
1513
1614end
17-
18-
19- function jpath = file2absPath(jfile )
20- % java.lang.System.getProperty('user.path') is stuck to where Java started
21-
22- jpath = jfile .toPath();
23-
24- if ~jfile .isAbsolute()
25- jpath = javaPathObject(pwd()).resolve(jpath );
26- end
27-
28- end
You can’t perform that action at this time.
0 commit comments