class EnClient::DBManager
Constants
- CONTENT_DIR
- DB_LOCK
- DB_NOTE
- DB_NOTEBOOK
- DB_SAVED_SEARCH
- DB_SYNC
- DB_SYNC_LAST_SYNC_FIELD
- DB_SYNC_USN_FIELD
- DB_TAG
- ENMODE_SYS_DIR
Public Class Methods
new()
click to toggle source
# File usr/lib/evernote-mode/enclient.rb, line 1262 def initialize unless FileTest.directory? ENMODE_SYS_DIR FileUtils.mkdir ENMODE_SYS_DIR end unless FileTest.directory? CONTENT_DIR FileUtils.mkdir CONTENT_DIR end @lock_file = open DB_LOCK, 'w' @mutex = Mutex.new @in_transaction = false @is_during_full_sync = false end
Public Instance Methods
clear_db()
click to toggle source
# File usr/lib/evernote-mode/enclient.rb, line 1288 def clear_db raise IllegalStateException.new("not in transaction") unless @in_transaction [DB_SYNC, DB_NOTEBOOK, DB_NOTE, DB_TAG, DB_SAVED_SEARCH].each do |file| GDBM.open file do |db| db.clear end end end
during_full_sync?()
click to toggle source
# File usr/lib/evernote-mode/enclient.rb, line 1342 def during_full_sync? result = nil @mutex.synchronize do result = @is_during_full_sync end result end
open_note(&block)
click to toggle source
# File usr/lib/evernote-mode/enclient.rb, line 1307 def open_note(&block) raise IllegalStateException.new("not in transaction") unless @in_transaction GDBM.open DB_NOTE, &block end
open_notebook(&block)
click to toggle source
# File usr/lib/evernote-mode/enclient.rb, line 1302 def open_notebook(&block) raise IllegalStateException.new("not in transaction") unless @in_transaction GDBM.open DB_NOTEBOOK, &block end
open_search(&block)
click to toggle source
# File usr/lib/evernote-mode/enclient.rb, line 1317 def open_search(&block) raise IllegalStateException.new("not in transaction") unless @in_transaction GDBM.open DB_SAVED_SEARCH, &block end
open_sync(&block)
click to toggle source
# File usr/lib/evernote-mode/enclient.rb, line 1297 def open_sync(&block) raise IllegalStateException.new("not in transaction") unless @in_transaction GDBM.open DB_SYNC, &block end
open_tag(&block)
click to toggle source
# File usr/lib/evernote-mode/enclient.rb, line 1312 def open_tag(&block) raise IllegalStateException.new("not in transaction") unless @in_transaction GDBM.open DB_TAG, &block end
remove_note_content(guid)
click to toggle source
# File usr/lib/evernote-mode/enclient.rb, line 1334 def remove_note_content(guid) raise IllegalStateException.new("not in transaction") unless @in_transaction file_path = CONTENT_DIR + guid LOG.info "try to expunge content at #{file_path}" FileUtils.rm file_path if FileTest.file? file_path LOG.info "expunge content at #{file_path}" end
set_during_full_sync(state)
click to toggle source
# File usr/lib/evernote-mode/enclient.rb, line 1350 def set_during_full_sync(state) LOG.debug "during full sync: #{state}" @mutex.synchronize do @is_during_full_sync = state end end
set_note_content(guid, content)
click to toggle source
note content
# File usr/lib/evernote-mode/enclient.rb, line 1324 def set_note_content(guid, content) raise IllegalStateException.new("not in transaction") unless @in_transaction file_path = CONTENT_DIR + guid open file_path, "w" do |file| # "w" for transform eols to the native ones file.write content end LOG.info "update content at #{file_path}" file_path end
transaction() { || ... }
click to toggle source
# File usr/lib/evernote-mode/enclient.rb, line 1277 def transaction @mutex.lock @lock_file.flock File::LOCK_EX @in_transaction = true yield ensure @in_transaction = false @lock_file.flock File::LOCK_UN @mutex.unlock end