Compare commits
3 Commits
0.9.41-bet
...
0.9.42-bet
| Author | SHA1 | Date | |
|---|---|---|---|
|
099201e4ad
|
|||
|
f8553b79f9
|
|||
|
ba6462458c
|
@@ -51,7 +51,7 @@ public class FilesystemLib {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (fs.stat(path).type != EntryType.FILE) {
|
if (fs.stat(path).type != EntryType.FILE) {
|
||||||
throw new FilesystemException(ErrorReason.DOESNT_EXIST, "Not a file").setAction(ActionType.OPEN);
|
throw new FilesystemException(ErrorReason.DOESNT_EXIST, "Not a file").setAction(ActionType.OPEN).setPath(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new FileLib(fs.open(path, _mode));
|
return new FileLib(fs.open(path, _mode));
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ public class Context implements Extensions {
|
|||||||
return new Context(ext);
|
return new Context(ext);
|
||||||
}
|
}
|
||||||
public static Extensions clean(Extensions ext) {
|
public static Extensions clean(Extensions ext) {
|
||||||
if (ext instanceof Context) return ((Context)ext).extensions;
|
if (ext instanceof Context) return clean(((Context)ext).extensions);
|
||||||
else return ext;
|
else return ext;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ public class GlobalScope {
|
|||||||
return Values.hasMember(ext, obj, name, false);
|
return Values.hasMember(ext, obj, name, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GlobalScope globalChild() {
|
public GlobalScope child() {
|
||||||
var obj = new ObjectValue();
|
var obj = new ObjectValue();
|
||||||
Values.setPrototype(null, obj, this.obj);
|
Values.setPrototype(null, obj, this.obj);
|
||||||
return new GlobalScope(obj);
|
return new GlobalScope(obj);
|
||||||
|
|||||||
@@ -89,7 +89,6 @@ public class JScriptRepl {
|
|||||||
private static void initEnv() {
|
private static void initEnv() {
|
||||||
environment = Internals.apply(environment);
|
environment = Internals.apply(environment);
|
||||||
|
|
||||||
var wp = NativeWrapperProvider.get(environment);
|
|
||||||
var glob = GlobalScope.get(environment);
|
var glob = GlobalScope.get(environment);
|
||||||
|
|
||||||
glob.define(null, false, new NativeFunction("exit", args -> {
|
glob.define(null, false, new NativeFunction("exit", args -> {
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ public abstract class BaseFile<T> implements File {
|
|||||||
@Override public synchronized long seek(long offset, int pos) {
|
@Override public synchronized long seek(long offset, int pos) {
|
||||||
try {
|
try {
|
||||||
if (handle == null) throw new FilesystemException(ErrorReason.CLOSED);
|
if (handle == null) throw new FilesystemException(ErrorReason.CLOSED);
|
||||||
if (!mode.writable) throw new FilesystemException(ErrorReason.NO_PERMISSION, "File not open for seeking.");
|
if (mode == Mode.NONE) throw new FilesystemException(ErrorReason.NO_PERMISSION, "File not open for seeking.");
|
||||||
return onSeek(offset, pos);
|
return onSeek(offset, pos);
|
||||||
}
|
}
|
||||||
catch (FilesystemException e) { throw e.setAction(ActionType.SEEK); }
|
catch (FilesystemException e) { throw e.setAction(ActionType.SEEK); }
|
||||||
|
|||||||
@@ -54,16 +54,12 @@ public class FilesystemException extends RuntimeException {
|
|||||||
@Override public String getMessage() {
|
@Override public String getMessage() {
|
||||||
var parts = new ArrayList<String>(10);
|
var parts = new ArrayList<String>(10);
|
||||||
|
|
||||||
path = String.join(" ", parts).trim();
|
|
||||||
if (path.isEmpty()) path = null;
|
|
||||||
parts.clear();
|
|
||||||
|
|
||||||
parts.add(action == null ? "An action performed upon " : action.readable(reason.usePast));
|
parts.add(action == null ? "An action performed upon " : action.readable(reason.usePast));
|
||||||
|
|
||||||
if (entry == EntryType.FILE) parts.add("file");
|
if (entry == EntryType.FILE) parts.add("file");
|
||||||
if (entry == EntryType.FOLDER) parts.add("folder");
|
if (entry == EntryType.FOLDER) parts.add("folder");
|
||||||
|
|
||||||
if (path != null) parts.add(path);
|
if (path != null && !path.isBlank()) parts.add(path.trim());
|
||||||
|
|
||||||
parts.add(reason.readable);
|
parts.add(reason.readable);
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package me.topchetoeu.jscript.utils.filesystem;
|
package me.topchetoeu.jscript.utils.filesystem;
|
||||||
|
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.FileAlreadyExistsException;
|
import java.nio.file.FileAlreadyExistsException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
@@ -35,7 +36,8 @@ public class PhysicalFilesystem implements Filesystem {
|
|||||||
));
|
));
|
||||||
else return handles.put(new PhysicalFile(path, perms));
|
else return handles.put(new PhysicalFile(path, perms));
|
||||||
}
|
}
|
||||||
catch (IOException e) { throw new FilesystemException(ErrorReason.DOESNT_EXIST); }
|
catch (FileNotFoundException e) { throw new FilesystemException(ErrorReason.DOESNT_EXIST); }
|
||||||
|
catch (IOException e) { throw new FilesystemException(ErrorReason.NO_PERMISSION); }
|
||||||
}
|
}
|
||||||
catch (FilesystemException e) { throw e.setAction(ActionType.OPEN).setPath(_path); }
|
catch (FilesystemException e) { throw e.setAction(ActionType.OPEN).setPath(_path); }
|
||||||
}
|
}
|
||||||
@@ -68,12 +70,7 @@ public class PhysicalFilesystem implements Filesystem {
|
|||||||
|
|
||||||
if (!Files.exists(path)) return new FileStat(Mode.NONE, EntryType.NONE);
|
if (!Files.exists(path)) return new FileStat(Mode.NONE, EntryType.NONE);
|
||||||
|
|
||||||
var perms = Mode.NONE;
|
var perms = Mode.of(Files.isReadable(path), Files.isWritable(path));
|
||||||
|
|
||||||
if (Files.isReadable(path)) {
|
|
||||||
if (Files.isWritable(path)) perms = Mode.READ_WRITE;
|
|
||||||
else perms = Mode.READ;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (perms == Mode.NONE) return new FileStat(Mode.NONE, EntryType.NONE);
|
if (perms == Mode.NONE) return new FileStat(Mode.NONE, EntryType.NONE);
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import me.topchetoeu.jscript.common.Filename;
|
|||||||
import me.topchetoeu.jscript.runtime.Context;
|
import me.topchetoeu.jscript.runtime.Context;
|
||||||
import me.topchetoeu.jscript.runtime.Extensions;
|
import me.topchetoeu.jscript.runtime.Extensions;
|
||||||
import me.topchetoeu.jscript.runtime.Key;
|
import me.topchetoeu.jscript.runtime.Key;
|
||||||
|
import me.topchetoeu.jscript.runtime.scope.GlobalScope;
|
||||||
import me.topchetoeu.jscript.utils.filesystem.Filesystem;
|
import me.topchetoeu.jscript.utils.filesystem.Filesystem;
|
||||||
import me.topchetoeu.jscript.utils.filesystem.Mode;
|
import me.topchetoeu.jscript.utils.filesystem.Mode;
|
||||||
|
|
||||||
@@ -25,8 +26,10 @@ public interface ModuleRepo {
|
|||||||
|
|
||||||
if (modules.containsKey(name)) return modules.get(name);
|
if (modules.containsKey(name)) return modules.get(name);
|
||||||
|
|
||||||
var env = ctx.extensions.child();
|
var env = Context.clean(ctx.extensions).child();
|
||||||
env.add(CWD, fs.normalize(name, ".."));
|
env.add(CWD, fs.normalize(name, ".."));
|
||||||
|
var glob = env.get(GlobalScope.KEY);
|
||||||
|
env.add(GlobalScope.KEY, glob.child());
|
||||||
|
|
||||||
var mod = new SourceModule(filename, src, env);
|
var mod = new SourceModule(filename, src, env);
|
||||||
modules.put(name, mod);
|
modules.put(name, mod);
|
||||||
|
|||||||
Reference in New Issue
Block a user