Skip to content

Commit

Permalink
Merge pull request #62 from internxt/fix/1.5.0-review
Browse files Browse the repository at this point in the history
[_]: fix/1.5.0-review
  • Loading branch information
aboredvaro authored Jan 7, 2022
2 parents e6868d4 + c870ba6 commit f2fd8c7
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 187 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "internxt-drive",
"version": "1.5.0",
"version": "1.5.1",
"author": "Internxt <[email protected]>",
"description": "Internxt Drive client UI",
"license": "AGPL-3.0",
Expand Down
6 changes: 3 additions & 3 deletions src/backup-process/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ function checkThatItExists(path) {
}

function getZipStream(backupPath) {
const archive = archiver('zip', { zlib: { level: 9 } })
const archive = archiver('zip', { store: true })

archive.directory(backupPath, false)

Expand All @@ -147,7 +147,7 @@ function getZipStream(backupPath) {

function zipAndHash(backupPath, fileEncryptionKey, index) {
return new Promise((resolve, reject) => {
const archive = archiver('zip', { zlib: { level: 9 } })
const archive = archiver('zip', { store: true })

archive.directory(backupPath, false)

Expand All @@ -161,7 +161,7 @@ function zipAndHash(backupPath, fileEncryptionKey, index) {

const encryptedHasher = new Environment.utils.Hasher()

pipeline(archive, hasher, cypher, encryptedHasher, console.log)
pipeline(archive, hasher, cypher, encryptedHasher, () => undefined)
.on('data', () => {})
.on('end', () => {
const plainHash = hasher.getHash().toString('hex')
Expand Down
8 changes: 8 additions & 0 deletions src/libs/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ let Logger = console
log.transports.file.maxSize = 1048576 * 150 // 150MB
log.transports.console.format = '[{iso}] [{level}] {text}'

if (process.env.NODE_ENV !== 'development') {
log.transports.file.level = 'info'
log.transports.console.level = 'error'
} else {
log.transports.file.level = 'silly'
log.transports.console.level = 'silly'
}

Logger = log

export default Logger
48 changes: 29 additions & 19 deletions src/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,22 @@ app.on('logged-in', startBackgroundProcesses)
function startBackgroundProcesses() {
checkUpdates()

// Check if we should launch sync process

const lastSync = ConfigStore.get('lastSync')

if (lastSync !== -1) {
const currentTimestamp = new Date().valueOf()

const millisecondsToNextSync = lastSync + SYNC_INTERVAL - currentTimestamp

if (millisecondsToNextSync <= 0) {
startSyncProcess()
} else {
syncProcessRerun = setTimeout(startSyncProcess, millisecondsToNextSync)
}
}

// Check if we should launch backup process

const backupInterval = ConfigStore.get('backupInterval')
Expand All @@ -614,22 +630,6 @@ function startBackgroundProcesses() {
}
}

// Check if we should launch sync process

const lastSync = ConfigStore.get('lastSync')

if (lastSync !== -1) {
const currentTimestamp = new Date().valueOf()

const millisecondsToNextSync = lastSync + SYNC_INTERVAL - currentTimestamp

if (millisecondsToNextSync <= 0) {
startSyncProcess()
} else {
syncProcessRerun = setTimeout(startSyncProcess, millisecondsToNextSync)
}
}

// Check updates every 6 hours
setInterval(() => {
checkUpdates()
Expand All @@ -639,7 +639,17 @@ function startBackgroundProcesses() {
let backupProcessStatus = BackupStatus.STANDBY
let backupProcessRerun = null

async function startBackupProcess() {
function waitForSyncToFinish() {
if (syncStatus === SyncStatus.STANDBY) return Promise.resolve()

return new Promise(resolve => {
app.once('sync-status-changed', resolve)
})
}

async function startBackupProcess(avoidRunningWithSync = true) {
if (avoidRunningWithSync) await waitForSyncToFinish()

const backupsAreEnabled = ConfigStore.get('backupsEnabled')

if (backupsAreEnabled && backupProcessStatus !== BackupStatus.IN_PROGRESS) {
Expand Down Expand Up @@ -714,7 +724,7 @@ async function startBackupProcess() {
}
}

ipcMain.on('start-backup-process', startBackupProcess)
ipcMain.on('start-backup-process', () => startBackupProcess(false))

ipcMain.handle('get-backup-status', () => backupProcessStatus)

Expand Down Expand Up @@ -763,7 +773,7 @@ function notifyBackupProcessWithNoConnection() {
notification.show()

notification.on('click', () => {
startBackupProcess()
startBackupProcess(false)
})
}

Expand Down
5 changes: 4 additions & 1 deletion src/renderer/components/SyncBottom/SyncBottom.vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ export default {
}
if (this.showUpdatedJustNow) {
setTimeout(() => (this.showUpdatedJustNow = false), 30 * 1000)
this.showUpdatedJustNowTimeout = setTimeout(
() => (this.showUpdatedJustNow = false),
30 * 1000
)
}
},
onStartClick() {
Expand Down
10 changes: 8 additions & 2 deletions src/renderer/components/SyncInfo/SyncInfo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
size="32"
class="flex-shrink-0 flex-grow-0"
/>
<div class="ml-2 flex-shrink flex-grow">
<div class="ml-2 flex-shrink flex-grow min-w-0">
<p class="text-sm truncate mt-1">
{{ item.name | showOnlyFilename }}
</p>
Expand Down Expand Up @@ -63,6 +63,7 @@ import path from 'path'
import FileIconWithOperation from '../Icons/FileIconWithOperation.vue'
import { shortMessages } from '../../../sync/sync-error-messages'
import { ipcRenderer } from 'electron'
import syncStatus from '../../../sync/sync-status'
const app = require('@electron/remote').app
export default {
Expand All @@ -79,10 +80,12 @@ export default {
},
mounted() {
app.on('SYNC_INFO_UPDATE', this.onInfoUpdate)
app.on('sync-status-changed', this.onSyncStatusChanged)
app.on('SYNC_NEXT', this.onNext)
},
beforeDestroy() {
app.removeListener('SYNC_INFO_UPDATE', this.onInfoUpdate)
app.removeListener('sync-status-changed', this.onSyncStatusChanged)
app.removeListener('SYNC_NEXT', this.onNext)
},
methods: {
Expand Down Expand Up @@ -113,8 +116,11 @@ export default {
this.items = itemsCopy
}
},
onSyncStatusChanged(newStatus) {
if (newStatus === syncStatus.RUNNING) this.items = []
},
onNext() {
this.items = []
this.items = this.items.filter(item => item.progress === undefined)
},
clear() {},
getStatusMessage(item) {
Expand Down
79 changes: 32 additions & 47 deletions src/sync/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Sync extends EventEmitter {
this.emit('CHECKING_LAST_RUN_OUTCOME')
const lastSavedListing = await this.listingStore.getLastSavedListing()

Logger.log('Last saved listing:', lastSavedListing)
Logger.debug('Last saved listing:', lastSavedListing)

if (!lastSavedListing) return this.resync()

Expand All @@ -33,14 +33,14 @@ class Sync extends EventEmitter {
emitErrors: true
})

Logger.log('Current local before', currentLocal)
Logger.log('Current remote before', currentRemote)
Logger.debug('Current local before', currentLocal)
Logger.debug('Current remote before', currentRemote)

const deltasLocal = this.generateDeltas(lastSavedListing, currentLocal)
const deltasRemote = this.generateDeltas(lastSavedListing, currentRemote)

Logger.log('Local deltas', deltasLocal)
Logger.log('Remote deltas', deltasRemote)
Logger.debug('Local deltas', deltasLocal)
Logger.debug('Remote deltas', deltasRemote)

const {
renameInLocal,
Expand All @@ -58,12 +58,12 @@ class Sync extends EventEmitter {

await this.listingStore.removeSavedListing()

Logger.log('Queue rename in local', renameInLocal)
Logger.log('Queue rename in remote', renameInRemote)
Logger.log('Queue pull from local', pullFromLocal)
Logger.log('Queue pull from remote', pullFromRemote)
Logger.log('Queue delete from local', deleteInLocal)
Logger.log('Queue delete from remote', deleteInRemote)
Logger.debug('Queue rename in local', renameInLocal)
Logger.debug('Queue rename in remote', renameInRemote)
Logger.debug('Queue pull from local', pullFromLocal)
Logger.debug('Queue pull from remote', pullFromRemote)
Logger.debug('Queue delete from local', deleteInLocal)
Logger.debug('Queue delete from remote', deleteInRemote)

await Promise.all([
this.consumeRenameQueue(renameInLocal, this.local),
Expand Down Expand Up @@ -101,38 +101,26 @@ class Sync extends EventEmitter {
emitErrors: true
})

Logger.log('Current local before', currentLocal)
Logger.log('Current remote before', currentRemote)
Logger.debug('Current local before', currentLocal)
Logger.debug('Current remote before', currentRemote)

const {
filesNotInLocal: pullFromLocal,
filesNotInRemote: pullFromRemote,
filesWithDifferentModtime
} = this.getListingsDiff(currentLocal, currentRemote)

const renameInLocal: [string, string][] = []
const renameInRemote: [string, string][] = []

for (const name of filesWithDifferentModtime) {
const localRenamed = this.rename(name, 'local')
const remoteRenamed = this.rename(name, 'remote')
const modtimeInLocal = currentLocal[name]
const modtimeInRemote = currentRemote[name]

renameInLocal.push([name, localRenamed])
renameInRemote.push([name, remoteRenamed])

pullFromLocal.push(remoteRenamed)
pullFromRemote.push(localRenamed)
if (modtimeInLocal < modtimeInRemote) pullFromLocal.push(name)
else pullFromRemote.push(name)
}

Logger.log('Queue rename in local', renameInLocal)
Logger.log('Queue rename in remote', renameInRemote)
Logger.log('Queue pull from local', pullFromLocal)
Logger.log('Queue pull from remote', pullFromRemote)
Logger.debug('Queue pull from local', pullFromLocal)
Logger.debug('Queue pull from remote', pullFromRemote)

await Promise.all([
this.consumeRenameQueue(renameInLocal, this.local),
this.consumeRenameQueue(renameInRemote, this.remote)
])
await Promise.all([
this.consumePullQueue(pullFromLocal, this.local, this.remote),
this.consumePullQueue(pullFromRemote, this.remote, this.local)
Expand Down Expand Up @@ -161,15 +149,12 @@ class Sync extends EventEmitter {
const deleteInLocal: string[] = []
const deleteInRemote: string[] = []

const renameAndKeepBoth = (name: string) => {
const localRenamed = this.rename(name, 'local')
const remoteRenamed = this.rename(name, 'remote')

renameInLocal.push([name, localRenamed])
renameInRemote.push([name, remoteRenamed])
const keepMostRecent = (name: string) => {
const modtimeInLocal = currentLocalListing[name]
const modtimeInRemote = currentRemoteListing[name]

pullFromLocal.push(remoteRenamed)
pullFromRemote.push(localRenamed)
if (modtimeInLocal < modtimeInRemote) pullFromLocal.push(name)
else pullFromRemote.push(name)
}

for (const [name, deltaLocal] of Object.entries(deltasLocal)) {
Expand All @@ -179,15 +164,15 @@ class Sync extends EventEmitter {
currentLocalListing[name] === currentRemoteListing[name]

if (deltaLocal === 'NEW' && deltaRemote === 'NEW' && !sameModTime) {
renameAndKeepBoth(name)
keepMostRecent(name)
}

if (deltaLocal === 'NEW' && doesntExistInRemote) {
pullFromRemote.push(name)
}

if (deltaLocal === 'NEWER' && deltaRemote === 'NEWER' && !sameModTime) {
renameAndKeepBoth(name)
keepMostRecent(name)
}

if (
Expand All @@ -198,7 +183,7 @@ class Sync extends EventEmitter {
}

if (deltaLocal === 'NEWER' && deltaRemote === 'OLDER') {
renameAndKeepBoth(name)
pullFromRemote.push(name)
}

if (
Expand All @@ -213,7 +198,7 @@ class Sync extends EventEmitter {
}

if (deltaLocal === 'OLDER' && deltaRemote === 'NEWER') {
renameAndKeepBoth(name)
pullFromLocal.push(name)
}

if (
Expand All @@ -224,7 +209,7 @@ class Sync extends EventEmitter {
}

if (deltaLocal === 'OLDER' && deltaRemote === 'OLDER' && !sameModTime) {
renameAndKeepBoth(name)
keepMostRecent(name)
}

if (
Expand Down Expand Up @@ -470,14 +455,14 @@ class Sync extends EventEmitter {

if (_.isEqual(currentLocal, currentRemote)) {
const currentInBoth = currentLocal
Logger.log('Current in both:', currentInBoth)
Logger.debug('Current in both:', currentInBoth)

await this.listingStore.saveListing(currentInBoth)

this.emit('DONE', { status: 'IN_SYNC' })
} else {
Logger.log('Current local:', currentLocal)
Logger.log('Current remote:', currentRemote)
Logger.debug('Current local:', currentLocal)
Logger.debug('Current remote:', currentRemote)

const diff = this.getListingsDiff(currentLocal, currentRemote)
this.emit('DONE', { status: 'NOT_IN_SYNC', diff })
Expand Down
Loading

0 comments on commit f2fd8c7

Please sign in to comment.