22
33const assert = require ( 'assert' )
44const fs = require ( 'fs' )
5+ const path = require ( 'path' )
56
67const crypto = require ( '../crypto' )
78const escodb = require ( '../escodb' )
@@ -10,8 +11,10 @@ const Reader = require('./reader')
1011class 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