mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-19 23:17:16 +03:00
Log a more informative message when cannot recover a file
This commit is contained in:
parent
c6a87b956e
commit
1a7858c9f1
@ -5,9 +5,10 @@ import FileRecoveryService from '../../src/main-process/file-recovery-service'
|
||||
import temp from 'temp'
|
||||
import fs from 'fs-plus'
|
||||
import {Emitter} from 'event-kit'
|
||||
import sinon from 'sinon'
|
||||
|
||||
describe("FileRecoveryService", () => {
|
||||
let recoveryService, recoveryDirectory, windows
|
||||
let recoveryService, recoveryDirectory, windows, previousConsoleLog
|
||||
|
||||
function createWindow () {
|
||||
const window = new BrowserWindow({show: false})
|
||||
@ -116,24 +117,23 @@ describe("FileRecoveryService", () => {
|
||||
})
|
||||
})
|
||||
|
||||
it("emits a warning when a file can't be recovered", () => {
|
||||
it("emits a warning when a file can't be recovered", sinon.test(function () {
|
||||
const mockWindow = createWindow()
|
||||
const filePath = temp.path()
|
||||
fs.writeFileSync(filePath, "content")
|
||||
fs.chmodSync(filePath, 0444)
|
||||
|
||||
const previousConsoleLog = console.log
|
||||
let logs = []
|
||||
console.log = (message) => logs.push(message)
|
||||
this.stub(console, 'log', (message) => logs.push(message))
|
||||
|
||||
recoveryService.willSavePath({sender: mockWindow.webContents}, filePath)
|
||||
mockWindow.webContents.emit("crashed")
|
||||
let recoveryFiles = fs.listTreeSync(recoveryDirectory)
|
||||
assert.equal(recoveryFiles.length, 1)
|
||||
assert.deepEqual(logs, [`Cannot recover ${filePath}. A recovery file has been saved here: ${recoveryFiles[0]}.`])
|
||||
|
||||
console.log = previousConsoleLog
|
||||
})
|
||||
assert.equal(logs.length, 1)
|
||||
assert.match(logs[0], new RegExp(filePath))
|
||||
assert.match(logs[0], new RegExp(recoveryFiles[0]))
|
||||
}))
|
||||
})
|
||||
|
||||
it("doesn't create a recovery file when the file that's being saved doesn't exist yet", () => {
|
||||
|
@ -1,6 +1,6 @@
|
||||
'use babel'
|
||||
|
||||
import {BrowserWindow, ipcMain} from 'electron'
|
||||
import {BrowserWindow, dialog, ipcMain} from 'electron'
|
||||
import crypto from 'crypto'
|
||||
import Path from 'path'
|
||||
import fs from 'fs-plus'
|
||||
@ -113,7 +113,10 @@ export default class FileRecoveryService {
|
||||
try {
|
||||
recoveryFile.recoverSync()
|
||||
} catch (error) {
|
||||
console.log(`Cannot recover ${recoveryFile.originalPath}. A recovery file has been saved here: ${recoveryFile.recoveryPath}.`)
|
||||
console.log(
|
||||
`There was a crash while saving "${recoveryFile.originalPath}", so this file might be blank or corrupted.\n` +
|
||||
`Atom couldn't recover it automatically, but a recovery file has been saved at: "${recoveryFile.recoveryPath}".`
|
||||
)
|
||||
} finally {
|
||||
this.recoveryFilesByFilePath.delete(recoveryFile.originalPath)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user