Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backup: Lots of fixes, refactoring and documentation #887

Merged
merged 18 commits into from
Aug 3, 2023

Conversation

zatteo
Copy link
Contributor

@zatteo zatteo commented Jul 28, 2023

No description provided.

zatteo added 13 commits July 27, 2023 20:30
For unknown error, there is now response body. So JSON.parse crash.
Updated TS types of patch-package.
Not totally agnostic. Linked to cozy-stack.

Will help next features link "share with".
When killing app during a backup, backup was stuck as running even if
it was not running. Now, if we start the app and backup is set as
running, we set it as to do because it is not possible. It is only
when app start, you we can still move between webview while a backup
is running
We try to stay as close as operating system :
- folder structure on Android
- album on iOS
On iOS, media are set with a remote path to '/' because there is no
folder in backup folder. But when restoring, remote path was set to
empty string so algorithm was considering these photos as not
backuped.
Backup folder is a magic folder. But in some part of the code, we
need to use the path of the backup folder from local backup config.
So now before uploading files, we check if the backup folder has been
renamed and we update local backup config if needed.
@zatteo zatteo requested a review from Crash-- July 28, 2023 18:55
name: newPhotosMagicFolder.name,
path: newPhotosMagicFolder.path
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pourquoi ne pas retourner tout newPhotosMagicFolder? 🤔


throw e
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

La méthode de cozy-client ne suffisait pas ?

@Crash-- Crash-- force-pushed the fix/backup-crash-rnbu branch 3 times, most recently from 0b56b06 to 33bc61b Compare August 1, 2023 06:38
Like that, cozy-stack is able to cut the connexion before the end if
there is no space left on the device.
This is how I use it : `./gradlew allDeps > allDeps.txt`
We have an http2 issue when uploading a file to a cozy when we reach the
quota limit. In that case, the stack closes the connexion but it can
appears after having already send a few bytes. In that case, okhttp was
not returning the right headers and we ended up with a:
`stream closed: cancel`.

With this version, okhttp is returning the right header!

see the okhttp changelog:
https://github.com/square/okhttp/blob/master/CHANGELOG.md#version-500-alpha1
specially:
`Fix: Attempt to read the response body even if the server canceled the
request. This will cause some calls to return nice error codes like
 HTTP/1.1 429 Too Many Requests instead of transport errors like
SocketException: Connection reset and StreamResetException: stream was
reset: CANCEL.
`
Copy link
Member

@Ldoppea Ldoppea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only change request is about the error.errors content check, other comments are nit.

export const isQuotaExceededError = (error: UploadError): boolean => {
return (
error.statusCode === 413 &&
error.errors[0].detail === 'The file is too big and exceeds the disk quota'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

error.errors content should be checked first here to prevent undefined access error if error[0] does not exist

export const setBackupAsToDo = async (client: CozyClient): Promise<void> => {
const localBackupConfig = await getLocalBackupConfig(client)

localBackupConfig.currentBackup.status = 'to_do'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Maybe to_do should be extracted as a global var?

}

void checkAndFixIfBackupStuckInRunning()
}, [client])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do we ensure this is called only on startup if there is a dependency on client? (however if the client changes I suppose it is expected to clear the backup status)

} catch (e) {
const error = e as UploadError

if (error.statusCode === 409) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Would be great to have an explicitly named method like for other methods (isQuotaExceededError, isFatalError etc) so we easily understand that this catch is about name conflicts

Previous implementation would throw if the received error do not
contain any `errors` array. this can happen if the error is not thrown
by cozy-client

Also this commit improve type check to ensure the receive error is the
one we expect. Casting objects using `as` should be avoided as this
will never ensure type compatibility
@Crash-- Crash-- merged commit 0f2e355 into master Aug 3, 2023
1 check passed
@Crash-- Crash-- deleted the fix/backup-crash-rnbu branch August 3, 2023 10:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants