Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP symlink, net_device virtio, move fixes, upload binary fixes #814

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/emulator/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,10 @@ window.onload = async function()
},
// bzimage_initrd_from_filesystem: true,
autostart: true,

network_relay_url: emu_config.network_relay ?? "wisp://127.0.0.1:4000",
net_device: {
relay_url: emu_config.network_relay ?? "wisp://127.0.0.1:4000",
type: "virtio"
},
virtio_console: true,
});

Expand Down
2 changes: 2 additions & 0 deletions src/puter-js/src/modules/FileSystem/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import read from "./operations/read.js";
import move from "./operations/move.js";
import write from "./operations/write.js";
import sign from "./operations/sign.js";
import symlink from './operations/symlink.js';
// Why is this called deleteFSEntry instead of just delete? because delete is
// a reserved keyword in javascript
import deleteFSEntry from "./operations/deleteFSEntry.js";
Expand All @@ -32,6 +33,7 @@ export class PuterJSFileSystemModule extends AdvancedBase {
move = move;
write = write;
sign = sign;
symlink = symlink;

static NARI_METHODS = {
stat: {
Expand Down
16 changes: 15 additions & 1 deletion src/puter-js/src/modules/FileSystem/operations/move.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import * as utils from '../../../lib/utils.js';
import getAbsolutePathForApp from '../utils/getAbsolutePathForApp.js';
import stat from "./stat.js"
import path from "../../../lib/path.js"

const move = function (...args) {
let options;

// If first argument is an object, it's the options
if (typeof args[0] === 'object' && args[0] !== null) {
options = args[0];
Expand Down Expand Up @@ -36,6 +37,19 @@ const move = function (...args) {
options.source = getAbsolutePathForApp(options.source);
options.destination = getAbsolutePathForApp(options.destination);

if (!options.new_name) {
// Handler to check if dest is supposed to be a file or a folder
try {
const destStats = await stat.bind(this)(options.destination); // this is meant to error if it doesn't exist
if (!destStats.is_dir) {
throw "is not directory" // just a wuick way to just to the catch
}
} catch (e) {
options.new_name = path.basename(options.destination);
options.destination = path.dirname(options.destination);
}
}

// create xhr object
const xhr = utils.initXhr('/move', this.APIOrigin, this.authToken);

Expand Down
55 changes: 55 additions & 0 deletions src/puter-js/src/modules/FileSystem/operations/symlink.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import getAbsolutePathForApp from '../utils/getAbsolutePathForApp.js';
import pathLib from '../../../lib/path.js';

// This only works for absolute symlinks for now
const symlink = async function (target, linkPath) {


// If auth token is not provided and we are in the web environment,
// try to authenticate with Puter
if(!puter.authToken && puter.env === 'web'){
try{
await puter.ui.authenticateWithPuter();
}catch(e){
// if authentication fails, throw an error
throw 'Authentication failed.';
}
}

// convert path to absolute path
linkPath = getAbsolutePathForApp(linkPath);
target = getAbsolutePathForApp(target);
const name = pathLib.basename(linkPath);
const linkDir = pathLib.dirname(linkPath)

const op =
{
op: 'symlink',
path: linkDir,
name: name,
target: target
};

const formData = new FormData();
formData.append('operation', JSON.stringify(op));

try {
const response = await fetch(this.APIOrigin + "/batch", {
method: 'POST',
headers: { 'Authorization': `Bearer ${puter.authToken}` },
body: formData
});
if (response.status !== 200) {
const error = await response.text();
console.error("[symlink] fetch error: ", error);
throw error;
}
} catch (e) {
console.error("[symlink] fetch error: ", e);
throw e;
}


}

export default symlink;
2 changes: 1 addition & 1 deletion src/puter-js/src/modules/FileSystem/operations/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ const upload = async function(items, dirPath, options = {}){
// blob
else if(items instanceof Blob){
// create a File object from the blob
let file = new File([items], options.name, { type: "text/plain" });
let file = new File([items], options.name, { type: "application/octet-stream" });
entries = [file];
// add FullPath property to each entry
for(let i=0; i<entries.length; i++){
Expand Down
2 changes: 1 addition & 1 deletion submodules/v86
Submodule v86 updated 10 files
+1 −1 Makefile
+1 −1 debug.html
+106 −56 index.html
+143 −83 lib/9p-puter.js
+194 −38 src/browser/main.js
+5 −1 src/cpu.js
+1 −0 src/lib.js
+98 −93 src/rust/cpu/cpu.rs
+1 −2 src/vga.js
+74 −11 v86.css