Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

File Recovery Service #11828

Merged
merged 34 commits into from
May 27, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
ef3ab03
Emit {will,did}SavePath on `ipcMain` before/after a buffer is saved
May 23, 2016
049321a
:bug: :fire: Remove double subscription to the same buffer
May 23, 2016
de599f9
Make dialog asynchronous when a renderer process crashes
May 23, 2016
b58ce49
Create `FileRecoveryService` to restore corrupted files after a crash
May 23, 2016
770199c
:art: event.sender -> window
May 23, 2016
ca32c13
:fire: Unnecessary variable assignments
May 23, 2016
57195d7
:white_check_mark: Write specs for FileRecoveryService
May 23, 2016
97dd25d
:green_heart:
May 24, 2016
25fece4
:art: file-recovery-service-spec.js -> file-recovery-service.spec.js
May 24, 2016
858740c
:memo: Better description on spec
May 24, 2016
c7f4b33
Emit informative warning when a file can't be recovered
May 24, 2016
4f1efe6
:shirt: Fix linter errors
May 24, 2016
7a12984
:fire: Unused requires on specs
May 24, 2016
152c28a
Merge branch 'master' into as-file-recovery-service
May 24, 2016
e57b35f
Merge branch 'master' into as-file-recovery-service
May 24, 2016
b84feeb
Emit {will,did}SavePath events synchronously
May 24, 2016
3b4c101
Forget window when it gets closed
May 25, 2016
c8fae11
Handle recovery when many windows save the same file simultaneously
May 25, 2016
3ce7d0a
Merge branch 'master' into as-file-recovery-service
May 25, 2016
3030723
:shirt: Fix linting issues
May 25, 2016
a2a734a
Generate readable recovery filenames
May 25, 2016
c6a87b9
Add sinon
May 25, 2016
1a7858c
Log a more informative message when cannot recover a file
May 25, 2016
c2b01d5
Make coupling looser between the recovery service and the windows
May 25, 2016
8ba275a
:art: Move RecoveryFile down
May 25, 2016
49a603a
Show also a message box when recovery is not successful
May 25, 2016
3f8f3c9
:fire: Remove extra comma
May 25, 2016
8733b52
:fire: Extra imports
May 25, 2016
d8564ad
Be a little more defensive when retaining/releasing recovery files
May 25, 2016
aefcbcd
:fire: Remove unneeded WeakSet
May 25, 2016
6c34844
:bug: Don't try to recover the same file twice
May 26, 2016
df263a2
Return early when a recovery file can't be stored
May 26, 2016
5e0e65b
Merge branch 'master' into as-file-recovery-service
May 26, 2016
8355e7f
Use fs.copyFileSync for buffered copy
May 26, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Log a more informative message when cannot recover a file
  • Loading branch information
Antonio Scandurra committed May 25, 2016
commit 1a7858c9f11bdeb4096bfc76fc62d16b0f05202d
16 changes: 8 additions & 8 deletions spec/main-process/file-recovery-service.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down Expand Up @@ -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", () => {
Expand Down
7 changes: 5 additions & 2 deletions src/main-process/file-recovery-service.js
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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)
}
Expand Down