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

feat(weavedrive): on read error halt process #410

Merged
merged 2 commits into from
Dec 17, 2024
Merged
Changes from 1 commit
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
14 changes: 9 additions & 5 deletions extensions/weavedrive/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,13 @@ module.exports = function weaveDrive (mod, FS) {
}

const node = FS.createFile('/', 'data/' + id, properties, true, false)

// Set initial parameters
const bytesLength = await this.customFetch(`/${id}`, { method: 'HEAD' }).then(res => res.headers.get('Content-Length'))
const response = await this.customFetch(`/${id}`, { method: 'HEAD' })
if (!response.ok) {
return 'HALT'
}
const bytesLength = response.headers.get('Content-Length')
node.total_size = Number(bytesLength)
node.cache = new Uint8Array(0)
node.position = 0
Expand Down Expand Up @@ -138,7 +143,6 @@ module.exports = function weaveDrive (mod, FS) {
async open (filename) {
const pathCategory = filename.split('/')[1]
const id = filename.split('/')[2]
console.log('JS: Opening ID: ', id)
if (pathCategory === 'tx') {
FS.createPath('/', 'tx', true, false)
if (FS.analyzePath(filename).exists) {
Expand All @@ -165,12 +169,12 @@ module.exports = function weaveDrive (mod, FS) {
if (FS.analyzePath(filename).exists) {
const stream = FS.open(filename, 'r')
if (stream.fd) return stream.fd
console.log('JS: File not found: ', filename)
return 0
} else {
// console.log("JS: Open => Creating file: ", id);
const stream = await this.create(id)
// console.log("JS: Open => Created file: ", id, " fd: ", stream.fd);
if (typeof stream === 'string') {
return 'HALT: FILE NOT FOUND'
}
return stream.fd
}
} else if (pathCategory === 'headers') {
Expand Down
Loading