Meriadec Pillet
6 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with
16 additions and
17 deletions
-
src/helpers/db/db.spec.js
-
src/helpers/db/index.js
-
src/helpers/fs.js
-
src/migrations/migrations.js
-
src/migrations/migrations.spec.js
|
|
@ -1,15 +1,12 @@ |
|
|
|
import os from 'os' |
|
|
|
import path from 'path' |
|
|
|
import fs from 'fs' |
|
|
|
import rimrafModule from 'rimraf' |
|
|
|
|
|
|
|
import db from 'helpers/db' |
|
|
|
import { promisify } from 'helpers/promise' |
|
|
|
import { fsReadFile, fsWriteFile, fsMkdir } from 'helpers/fs' |
|
|
|
|
|
|
|
const rimraf = promisify(rimrafModule) |
|
|
|
const fsReadFile = promisify(fs.readFile) |
|
|
|
const fsWriteFile = promisify(fs.writeFile) |
|
|
|
const fsMkdir = promisify(fs.mkdir) |
|
|
|
|
|
|
|
const accountsTransform = { |
|
|
|
get: accounts => accounts.map(account => ({ ...account, balance: Number(account.balance) })), |
|
|
|
|
|
@ -1,6 +1,5 @@ |
|
|
|
// @flow
|
|
|
|
|
|
|
|
import fs from 'fs' |
|
|
|
import path from 'path' |
|
|
|
import crypto from 'crypto' |
|
|
|
import cloneDeep from 'lodash/cloneDeep' |
|
|
@ -9,6 +8,7 @@ import get from 'lodash/get' |
|
|
|
import set from 'lodash/set' |
|
|
|
|
|
|
|
import logger from 'logger' |
|
|
|
import { fsReadFile, fsUnlink } from 'helpers/fs' |
|
|
|
import { promisify, debounce } from 'helpers/promise' |
|
|
|
|
|
|
|
import { NoDBPathGiven, DBWrongPassword } from 'config/errors' |
|
|
@ -18,8 +18,6 @@ type Transform = { |
|
|
|
set: any => any, |
|
|
|
} |
|
|
|
|
|
|
|
const fsReadFile = promisify(fs.readFile) |
|
|
|
const fsUnlink = promisify(fs.unlink) |
|
|
|
const writeFileAtomic = promisify(writeFileAtomicModule) |
|
|
|
|
|
|
|
const ALGORITHM = 'aes-256-cbc' |
|
|
|
|
|
@ -0,0 +1,10 @@ |
|
|
|
// @flow
|
|
|
|
|
|
|
|
import { promisify } from 'helpers/promise' |
|
|
|
import fs from 'fs' |
|
|
|
|
|
|
|
export const fsReadFile = promisify(fs.readFile) |
|
|
|
export const fsReaddir = promisify(fs.readdir) |
|
|
|
export const fsWriteFile = promisify(fs.writeFile) |
|
|
|
export const fsMkdir = promisify(fs.mkdir) |
|
|
|
export const fsUnlink = promisify(fs.unlink) |
|
|
@ -1,16 +1,12 @@ |
|
|
|
// @flow
|
|
|
|
|
|
|
|
import fs from 'fs' |
|
|
|
import path from 'path' |
|
|
|
|
|
|
|
import { promisify } from 'helpers/promise' |
|
|
|
import { fsReadFile, fsUnlink } from 'helpers/fs' |
|
|
|
import db from 'helpers/db' |
|
|
|
|
|
|
|
import type { Migration } from './types' |
|
|
|
|
|
|
|
const fsReadfile = promisify(fs.readFile) |
|
|
|
const fsUnlink = promisify(fs.unlink) |
|
|
|
|
|
|
|
const migrations: Migration[] = [ |
|
|
|
{ |
|
|
|
doc: 'merging multiple db files into one app file', |
|
|
@ -54,13 +50,13 @@ async function getFileData(dbPath, fileName) { |
|
|
|
const filePath = path.join(dbPath, `${fileName}.json`) |
|
|
|
let finalData |
|
|
|
try { |
|
|
|
const fileContent = await fsReadfile(filePath, 'utf-8') |
|
|
|
const fileContent = await fsReadFile(filePath, 'utf-8') |
|
|
|
const { data } = JSON.parse(fileContent) |
|
|
|
finalData = data |
|
|
|
} catch (err) { |
|
|
|
// we assume we are in that case because file is encrypted
|
|
|
|
if (err instanceof SyntaxError) { |
|
|
|
const buf = await fsReadfile(filePath) |
|
|
|
const buf = await fsReadFile(filePath) |
|
|
|
return buf.toString('base64') |
|
|
|
} |
|
|
|
// will be stripped down by JSON.stringify
|
|
|
|
|
|
@ -1,4 +1,3 @@ |
|
|
|
import fs from 'fs' |
|
|
|
import os from 'os' |
|
|
|
import path from 'path' |
|
|
|
import { spawn } from 'child_process' |
|
|
@ -6,13 +5,12 @@ import rimrafModule from 'rimraf' |
|
|
|
import { BigNumber } from 'bignumber.js' |
|
|
|
|
|
|
|
import { promisify } from 'helpers/promise' |
|
|
|
import { fsReadFile, fsReaddir } from 'helpers/fs' |
|
|
|
import { runMigrations } from 'migrations' |
|
|
|
import { decodeAccountsModel, encodeAccountsModel } from 'reducers/accounts' |
|
|
|
import db from 'helpers/db' |
|
|
|
|
|
|
|
const rimraf = promisify(rimrafModule) |
|
|
|
const fsReaddir = promisify(fs.readdir) |
|
|
|
const fsReadFile = promisify(fs.readFile) |
|
|
|
|
|
|
|
const tmpDir = os.tmpdir() |
|
|
|
|
|
|
|