Skip to content

Commit 8caebca

Browse files
committed
raise if it's not a regular file
1 parent 246b509 commit 8caebca

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

extension/android/executorch_android/src/main/java/org/pytorch/executorch/Module.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ public static Module load(final String modelPath, int loadMode) {
5353
if (!NativeLoader.isInitialized()) {
5454
NativeLoader.init(new SystemDelegate());
5555
}
56-
if (!new File(modelPath).canRead()) {
56+
File modelFile = new File(modelPath);
57+
if (!modelFile.canRead() || !modelFile.isFile()) {
5758
throw new RuntimeException("Cannot load model path " + modelPath);
5859
}
5960
return new Module(new NativePeer(modelPath, loadMode));

extension/android/executorch_android/src/main/java/org/pytorch/executorch/extension/llm/LlmModule.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,12 @@ private static native HybridData initHybrid(
4848
*/
4949
public LlmModule(
5050
int modelType, String modulePath, String tokenizerPath, float temperature, String dataPath) {
51-
if (!new File(modulePath).canRead()) {
51+
File modelFile = new File(modulePath);
52+
if (!modelFile.canRead() || !modelFile.isFile()) {
5253
throw new RuntimeException("Cannot load model path " + modulePath);
5354
}
54-
if (!new File(tokenizerPath).canRead()) {
55+
File tokenizerFile = new File(tokenizerPath);
56+
if (!tokenizerFile.canRead() || !tokenizerFile.isFile()) {
5557
throw new RuntimeException("Cannot load tokenizer path " + tokenizerPath);
5658
}
5759
mHybridData = initHybrid(modelType, modulePath, tokenizerPath, temperature, dataPath);

0 commit comments

Comments
 (0)