Add support for fgetattr and symlinks
This commit is contained in:
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 { NodeDescriptorType } = require('../../enum')
|
||||
const { NodeDescriptorType, NodeModeType } = require('../../enum')
|
||||
|
||||
module.exports = exports = async (message, di) => {
|
||||
const Node = di.models.get('fs:Node')
|
||||
@@ -29,7 +29,7 @@ module.exports = exports = async (message, di) => {
|
||||
pied_name,
|
||||
pied_parent_path,
|
||||
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,
|
||||
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(
|
||||
message.fresh().error(Errors.IsDirectoryDescriptor)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user