Skip to content
Open
Changes from all commits
Commits
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
34 changes: 10 additions & 24 deletions src/node_sqlite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ class BackupJob : public ThreadPoolWork {
std::string dest_db,
int pages,
Local<Function> progressFunc)
: ThreadPoolWork(env, "node_sqlite3.BackupJob"),
: ThreadPoolWork(env, "node.sqlite.BackupJob"),
env_(env),
source_(source),
pages_(pages),
Expand Down Expand Up @@ -498,7 +498,7 @@ class BackupJob : public ThreadPoolWork {

if (!(backup_status_ == SQLITE_OK || backup_status_ == SQLITE_DONE ||
backup_status_ == SQLITE_BUSY || backup_status_ == SQLITE_LOCKED)) {
HandleBackupError(resolver, backup_status_);
HandleBackupError(resolver);
return;
}

Expand Down Expand Up @@ -549,11 +549,6 @@ class BackupJob : public ThreadPoolWork {
}

void Finalize() {
Cleanup();
source_->RemoveBackup(this);
}

void Cleanup() {
if (backup_) {
sqlite3_backup_finish(backup_);
backup_ = nullptr;
Expand All @@ -564,29 +559,20 @@ class BackupJob : public ThreadPoolWork {
sqlite3_close_v2(dest_);
dest_ = nullptr;
}

source_->RemoveBackup(this);
}

private:
void HandleBackupError(Local<Promise::Resolver> resolver) {
Local<Object> e;
if (!CreateSQLiteError(env()->isolate(), dest_).ToLocal(&e)) {
Finalize();
return;
}

auto error = sqlite3_errcode(dest_) == SQLITE_OK
? CreateSQLiteError(env()->isolate(), backup_status_)
: CreateSQLiteError(env()->isolate(), dest_);
Finalize();
resolver->Reject(env()->context(), e).ToChecked();
}

void HandleBackupError(Local<Promise::Resolver> resolver, int errcode) {
Local<Object> e;
if (!CreateSQLiteError(env()->isolate(), errcode).ToLocal(&e)) {
Finalize();
return;
if (error.ToLocal(&e)) {
resolver->Reject(env()->context(), e).ToChecked();
}

Finalize();
resolver->Reject(env()->context(), e).ToChecked();
}

Environment* env() const { return env_; }
Expand Down Expand Up @@ -781,7 +767,7 @@ bool DatabaseSync::Open() {

void DatabaseSync::FinalizeBackups() {
for (auto backup : backups_) {
backup->Cleanup();
backup->Finalize();
}

backups_.clear();
Expand Down
Loading