Skip to content

Commit 07a88e8

Browse files
committed
Place migration files in the same directory as the original file to avoid cross-device file move problems
1 parent b92d21f commit 07a88e8

2 files changed

Lines changed: 15 additions & 11 deletions

File tree

lib/legacy/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ async function migrate (logger, pathname, password) {
1818
if (!stat.isFile()) return false
1919

2020
message(
21-
'It looks as though your config file (' + pathname + ') was created ' +
22-
'with an old version of Vault. In order to continue, it needs to be ' +
23-
'converted to a new format.')
21+
'It looks as though your config file (' + pathname + ') was created with ' +
22+
'old version of Vault. In order to continue, it needs to be converted to ' +
23+
'a new format. You should back up your existing config file before ' +
24+
'continuing.')
2425

2526
await confirm('Would you like Vault to perform this conversion now?')
2627

lib/legacy/migrator.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const assert = require('assert')
44
const fs = require('fs')
5+
const path = require('path')
56

67
const crypto = require('../crypto')
78
const escodb = require('../escodb')
@@ -10,8 +11,10 @@ const Reader = require('./reader')
1011
class Migrator {
1112
constructor ({ logger, pathname, password }) {
1213
this._logger = logger
13-
this._filename = pathname
1414
this._password = password
15+
16+
this._pathname = pathname
17+
this._dirname = path.dirname(pathname)
1518
};
1619

1720
log (message) {
@@ -30,12 +33,12 @@ class Migrator {
3033
}
3134

3235
_readInputFile () {
33-
this.log('reading input file: ' + this._filename)
36+
this.log('reading input file: ' + this._pathname)
3437

3538
try {
36-
this._content = fs.readFileSync(this._filename, 'utf8')
39+
this._content = fs.readFileSync(this._pathname, 'utf8')
3740
} catch (error) {
38-
throw new Error('file is unreadable: ' + this._filename)
41+
throw new Error('file is unreadable: ' + this._pathname)
3942
}
4043
}
4144

@@ -49,7 +52,7 @@ class Migrator {
4952
}
5053

5154
async _createStore () {
52-
this._storepath = '/tmp/vault-convert-' + random()
55+
this._storepath = path.join(this._dirname, 'vault-convert-' + random())
5356
this.log('creating new storage target: ' + this._storepath)
5457

5558
let adapter = escodb.createFileAdapter(this._storepath)
@@ -80,10 +83,10 @@ class Migrator {
8083
}
8184

8285
_swapFiles () {
83-
this._backuppath = '/tmp/vault-backup-' + random()
86+
this._backuppath = path.join(this._dirname, 'vault-backup-' + random())
8487

85-
this._rename(this._filename, this._backuppath)
86-
this._rename(this._storepath, this._filename)
88+
this._rename(this._pathname, this._backuppath)
89+
this._rename(this._storepath, this._pathname)
8790
}
8891

8992
_rename (a, b) {

0 commit comments

Comments
 (0)