Skip to content

Commit

Permalink
electron: copy if can't rename
Browse files Browse the repository at this point in the history
  • Loading branch information
shadow-light committed Oct 14, 2024
1 parent 8cb25b8 commit 4fa8551
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions electron/src/setup/data.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

import {join} from 'path'
import {existsSync, renameSync, mkdirSync, writeFileSync} from 'original-fs'
import {existsSync, renameSync, mkdirSync, writeFileSync, cpSync} from 'original-fs'

import {app} from 'electron'

Expand Down Expand Up @@ -40,5 +40,11 @@ app.setPath('userData', electron_user_data)

// Move old data if exists (location is only set if new data doesn't already exist)
if (old_data_location){
renameSync(old_data_location, electron_user_data)
try {
renameSync(old_data_location, electron_user_data)
} catch {
// Rename can sometimes fail on Windows if something else has opened a file
// WARN Only copy as a backup as some users will have GBs of data
cpSync(old_data_location, electron_user_data, {recursive: true})
}
}

0 comments on commit 4fa8551

Please sign in to comment.