Add support for fgetattr and symlinks
This commit is contained in:
parent
bb4a786b41
commit
8e57578251
@ -1,6 +1,13 @@
|
|||||||
const NodeDescriptorType = {
|
const NodeDescriptorType = {
|
||||||
File: 'file',
|
File: 'file',
|
||||||
Directory: 'directory',
|
Directory: 'directory',
|
||||||
|
Symlink: 'symlink',
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = exports = { NodeDescriptorType }
|
const NodeModeType = {
|
||||||
|
File: 33188,
|
||||||
|
Directory: 16877,
|
||||||
|
Symlink: 40960,
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = exports = { NodeDescriptorType, NodeModeType }
|
@ -1,6 +1,6 @@
|
|||||||
const uuid = require('uuid').v4
|
const uuid = require('uuid').v4
|
||||||
const { Model } = require('flitter-orm')
|
const { Model } = require('flitter-orm')
|
||||||
const { NodeDescriptorType } = require('../../enum')
|
const { NodeDescriptorType, NodeModeType } = require('../../enum')
|
||||||
|
|
||||||
class Node extends Model {
|
class Node extends Model {
|
||||||
static get services() {
|
static get services() {
|
||||||
@ -16,12 +16,14 @@ class Node extends Model {
|
|||||||
mtime: { type: Date, default: () => new Date },
|
mtime: { type: Date, default: () => new Date },
|
||||||
atime: { type: Date, default: () => new Date },
|
atime: { type: Date, default: () => new Date },
|
||||||
ctime: { type: Date, default: () => new Date },
|
ctime: { type: Date, default: () => new Date },
|
||||||
mode: { type: Number, default: 33188 },
|
mode: { type: Number, default: NodeModeType.File },
|
||||||
size: { type: Number, default: 0 },
|
size: { type: Number, default: 0 },
|
||||||
|
|
||||||
descriptor_type: { type: String, default: NodeDescriptorType.File },
|
descriptor_type: { type: String, default: NodeDescriptorType.File },
|
||||||
uploaded_file_id: String,
|
uploaded_file_id: String,
|
||||||
|
|
||||||
|
symlink_path: String, // If NodeDescriptorType.Symlink, the path to resolve
|
||||||
|
|
||||||
extended_attributes: [{
|
extended_attributes: [{
|
||||||
name: String,
|
name: String,
|
||||||
value: String, // base64 encoded binary buffer value
|
value: String, // base64 encoded binary buffer value
|
||||||
@ -50,7 +52,7 @@ class Node extends Model {
|
|||||||
if ( !root ) {
|
if ( !root ) {
|
||||||
root = new this({
|
root = new this({
|
||||||
pied_name: '/',
|
pied_name: '/',
|
||||||
mode: 16877,
|
mode: NodeModeType.Directory,
|
||||||
root: true,
|
root: true,
|
||||||
descriptor_type: NodeDescriptorType.Directory,
|
descriptor_type: NodeDescriptorType.Directory,
|
||||||
})
|
})
|
||||||
|
31
app/ws/routes/fs.fgetattr.js
Normal file
31
app/ws/routes/fs.fgetattr.js
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
const { Errors } = require('../../shared')
|
||||||
|
const { NodeDescriptorType } = require('../../enum')
|
||||||
|
|
||||||
|
// TODO should this return size info for the temp write file?
|
||||||
|
module.exports = exports = async (message, di) => {
|
||||||
|
const Node = di.models.get('fs:Node')
|
||||||
|
const { descriptor } = message.data()
|
||||||
|
|
||||||
|
const node_uuid = message.socket.session.file_descriptors?.[descriptor]
|
||||||
|
if ( !node_uuid ) {
|
||||||
|
return message.send_response(
|
||||||
|
message.fresh().error(Errors.NodeDoesNotExist)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const node = await Node.findOne({
|
||||||
|
uuid: node_uuid,
|
||||||
|
deleted: false,
|
||||||
|
descriptor_type: NodeDescriptorType.File,
|
||||||
|
})
|
||||||
|
|
||||||
|
if ( !node ) {
|
||||||
|
return message.send_response(
|
||||||
|
message.fresh().error(Errors.NodeDoesNotExist)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
message.send_response(
|
||||||
|
message.fresh().data({ node: node.to_api() })
|
||||||
|
)
|
||||||
|
}
|
@ -1,5 +1,5 @@
|
|||||||
const { Errors } = require('../../shared')
|
const { Errors } = require('../../shared')
|
||||||
const { NodeDescriptorType } = require('../../enum')
|
const { NodeDescriptorType, NodeModeType } = require('../../enum')
|
||||||
|
|
||||||
module.exports = exports = async (message, di) => {
|
module.exports = exports = async (message, di) => {
|
||||||
const Node = di.models.get('fs:Node')
|
const Node = di.models.get('fs:Node')
|
||||||
@ -29,7 +29,7 @@ module.exports = exports = async (message, di) => {
|
|||||||
pied_name,
|
pied_name,
|
||||||
pied_parent_path,
|
pied_parent_path,
|
||||||
overlay_name: message.socket.session.overlay_name || 'mainline',
|
overlay_name: message.socket.session.overlay_name || 'mainline',
|
||||||
mode: 16877, // TODO account for the mode from the client!
|
mode: NodeModeType.Directory, // TODO account for the mode from the client!
|
||||||
descriptor_type: NodeDescriptorType.Directory,
|
descriptor_type: NodeDescriptorType.Directory,
|
||||||
size: 100,
|
size: 100,
|
||||||
})
|
})
|
||||||
|
24
app/ws/routes/fs.readlink.js
Normal file
24
app/ws/routes/fs.readlink.js
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
const { Errors } = require('../../shared')
|
||||||
|
const { NodeDescriptorType } = require('../../enum')
|
||||||
|
|
||||||
|
module.exports = exports = async (message, di) => {
|
||||||
|
const Node = di.models.get('fs:Node')
|
||||||
|
const { path } = message.data()
|
||||||
|
|
||||||
|
const node = await Node.get_path(path, message.socket.session.overlay_name || 'mainline')
|
||||||
|
if ( !node ) {
|
||||||
|
return message.send_response(
|
||||||
|
message.fresh().error(Errors.NodeDoesNotExist)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( node.descriptor_type !== NodeDescriptorType.Symlink ) {
|
||||||
|
return message.send_response(
|
||||||
|
message.fresh().error(Errors.NodeAlreadyExists)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
message.send_response(
|
||||||
|
message.fresh().data({ node: node.to_api(), link: node.symlink_path })
|
||||||
|
)
|
||||||
|
}
|
31
app/ws/routes/fs.symlink.js
Normal file
31
app/ws/routes/fs.symlink.js
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
const { Errors } = require('../../shared')
|
||||||
|
const { NodeDescriptorType, NodeModeType } = require('../../enum')
|
||||||
|
|
||||||
|
module.exports = exports = async (message, di) => {
|
||||||
|
const Node = di.models.get('fs:Node')
|
||||||
|
const { source, destination } = message.data()
|
||||||
|
|
||||||
|
const destination_node = await Node.get_path(destination, message.socket.session.overlay_name || 'mainline')
|
||||||
|
if ( destination_node ) {
|
||||||
|
destination_node.deleted = true
|
||||||
|
await destination_node.save()
|
||||||
|
}
|
||||||
|
|
||||||
|
const [pied_parent_path, pied_name] = Node.path_parts(destination)
|
||||||
|
const node = new Node({
|
||||||
|
pied_name,
|
||||||
|
pied_parent_path,
|
||||||
|
overlay_name: message.socket.session.overlay_name || 'mainline',
|
||||||
|
descriptor_type: NodeDescriptorType.Symlink,
|
||||||
|
symlink_path: source,
|
||||||
|
mode: NodeModeType.Symlink,
|
||||||
|
})
|
||||||
|
|
||||||
|
await node.save()
|
||||||
|
|
||||||
|
console.log('symlink node', node)
|
||||||
|
|
||||||
|
message.send_response(
|
||||||
|
message.fresh().data({ node: node.to_api() })
|
||||||
|
)
|
||||||
|
}
|
@ -24,7 +24,7 @@ module.exports = exports = async (message, di) => {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( node.descriptor_type !== NodeDescriptorType.File ) {
|
if ( node.descriptor_type === NodeDescriptorType.Directory ) {
|
||||||
return message.send_response(
|
return message.send_response(
|
||||||
message.fresh().error(Errors.IsDirectoryDescriptor)
|
message.fresh().error(Errors.IsDirectoryDescriptor)
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user