Skip to content

Commit bc8bc6b

Browse files
committed
Added symlink + mkdir/symlink test
1 parent acf7136 commit bc8bc6b

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

lib/drives/index.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,14 +444,19 @@ class DriveManager extends EventEmitter {
444444
mkdir: async (call) => {
445445
const id = call.request.getId()
446446
const path = call.request.getPath()
447-
const mode = call.request.getMode()
447+
const opts = fromStat(call.request.getOpts())
448448

449449
if (!id) throw new Error('A mkdir request must specify a session ID.')
450450
if (!path) throw new Error('A mkdir request must specify a directory path.')
451451
const drive = this.driveForSession(id)
452452

453+
const mkdirOpts = {}
454+
if (opts.uid) mkdirOpts.uid = opts.uid
455+
if (opts.gid) mkdirOpts.gid = opts.gid
456+
if (opts.mode) mkdirOpts.mode = opts.mode
457+
453458
return new Promise((resolve, reject) => {
454-
drive.mkdir(path, mode, err => {
459+
drive.mkdir(path, mkdirOpts, err => {
455460
if (err) return reject(err)
456461

457462
const rsp = new rpc.drive.messages.MkdirResponse()
@@ -569,6 +574,26 @@ class DriveManager extends EventEmitter {
569574
}
570575
},
571576

577+
symlink: async (call) => {
578+
const id = call.request.getId()
579+
const target = call.request.getTarget()
580+
const linkname = call.request.getLinkname()
581+
582+
if (!id) throw new Error('A symlink request must specify a session ID.')
583+
if (!target) throw new Error('A symlink request must specify a target.')
584+
if (!linkname) throw new Error('A symlink request must specify a linkname.')
585+
const drive = this.driveForSession(id)
586+
587+
return new Promise((resolve, reject) => {
588+
drive.symlink(target, linkname, err => {
589+
if (err) return reject(err)
590+
591+
const rsp = new rpc.drive.messages.SymlinkResponse()
592+
return resolve(rsp)
593+
})
594+
})
595+
},
596+
572597
close: async (call) => {
573598
const id = call.request.getId()
574599

test/hyperdrive.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,32 @@ test.skip('watch cleans up after unexpected close', async t => {
294294
t.end()
295295
})
296296

297+
test('can create a symlink to directories', async t => {
298+
const { client, cleanup } = await createOne()
299+
300+
try {
301+
const drive = await client.drive.get()
302+
await drive.mkdir('hello', { uid: 999 })
303+
await drive.writeFile('hello/world', 'content')
304+
await drive.symlink('hello', 'other_hello')
305+
await drive.symlink('hello/world', 'other_world')
306+
307+
const contents = await drive.readFile('other_world')
308+
t.same(contents, Buffer.from('content'))
309+
310+
const files = await drive.readdir('other_hello')
311+
t.same(files.length, 1)
312+
t.same(files[0], 'world')
313+
314+
await drive.close()
315+
} catch (err) {
316+
t.fail(err)
317+
}
318+
319+
await cleanup()
320+
t.end()
321+
})
322+
297323
// TODO: Figure out why the grpc server is not terminating.
298324
test.onFinish(() => {
299325
setTimeout(() => {

0 commit comments

Comments
 (0)