mirror of
https://github.com/wassname/nvatom.git
synced 2026-08-11 11:22:13 +08:00
Fix #25 so that it ensures the note directory does not nest within the package directory
This commit is contained in:
@@ -8,12 +8,12 @@ module.exports =
|
||||
title: 'Note Directory'
|
||||
description: 'The directory to archive notes'
|
||||
type: 'string'
|
||||
default: process.env.ATOM_HOME + '/packages/notational-velocity/notebook'
|
||||
default: path.join(process.env.ATOM_HOME, 'notational-velocity-notes')
|
||||
|
||||
notationalVelocityView: null
|
||||
|
||||
activate: (state) ->
|
||||
@rootDirectory = fs.realpathSync(atom.config.get('notational-velocity.directory'))
|
||||
@rootDirectory = @ensureNoteDirectory()
|
||||
|
||||
# Events subscribed to in atom's system can be easily cleaned up with a
|
||||
# CompositeDisposable
|
||||
@@ -60,3 +60,25 @@ module.exports =
|
||||
|
||||
autosaveAll: ->
|
||||
@autosave(paneItem) for paneItem in atom.workspace.getPaneItems()
|
||||
|
||||
ensureNoteDirectory: ->
|
||||
noteDirectory = atom.config.get('notational-velocity.directory')
|
||||
packagesDirectory = path.join(process.env.ATOM_HOME, 'packages')
|
||||
defaultNoteDirectory = path.join(packagesDirectory, 'notational-velocity', 'notebook')
|
||||
|
||||
if noteDirectory.startsWith(packagesDirectory)
|
||||
storageDirectory = path.join(packagesDirectory, 'storage')
|
||||
throw new Error("""
|
||||
The note directory (#{noteDirectory}) should NOT nest under #{packagesDirectory}.
|
||||
It is likely that you updated the package to a newer version from v0.1.0.
|
||||
It is likely that the note directory is overwritten.
|
||||
Unfortunately, I couldn't find a way to recover overwritten notes.
|
||||
You might recover partial notes from #{storageDirectory}.
|
||||
I am extremely sorry.
|
||||
- Seongjae Lee""")
|
||||
|
||||
if !fs.existsSync(noteDirectory)
|
||||
fs.makeTreeSync(noteDirectory)
|
||||
fs.copySync(defaultNoteDirectory, noteDirectory)
|
||||
|
||||
return fs.realpathSync(noteDirectory)
|
||||
|
||||
Reference in New Issue
Block a user