backup-constants.mjs (3894B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 export const ERRORS = Object.freeze({ 6 /** Error state to be used for error management */ 7 NONE: 0, 8 /** User is not authorized to restore a backup archive */ 9 UNAUTHORIZED: 1, 10 /** Selected backup archive can't be restored because it is corrupt */ 11 CORRUPTED_ARCHIVE: 2, 12 /** 13 * Selected backup archive can't be restored because the backup manifest 14 * version is too old, from the future, or invalid 15 */ 16 UNSUPPORTED_BACKUP_VERSION: 3, 17 /** Backup service was not started or is not running */ 18 UNINITIALIZED: 4, 19 /** Could not read from or write to the file system */ 20 FILE_SYSTEM_ERROR: 5, 21 /** Encryption of backup archive failed */ 22 ENCRYPTION_FAILED: 6, 23 /** Decryption of backup archive failed */ 24 DECRYPTION_FAILED: 7, 25 /** Recovery of backup failed without a more specific cause */ 26 RECOVERY_FAILED: 8, 27 /** Unknown error with backup system without a more specific cause */ 28 UNKNOWN: 9, 29 /** 30 * Backup system tried to enable backup encryption but it was 31 * already enabled 32 */ 33 ENCRYPTION_ALREADY_ENABLED: 10, 34 /** 35 * Backup system tried to disable backup encryption but it was 36 * already disabled 37 */ 38 ENCRYPTION_ALREADY_DISABLED: 11, 39 /** User supplied a new password that is not a valid password */ 40 INVALID_PASSWORD: 12, 41 /** 42 * An error internal to the code that is likely caused by a bug 43 * or other programmer error. 44 */ 45 INTERNAL_ERROR: 13, 46 /** 47 * A backup cannot be recovered because the backup file was created 48 * by a different application than the currently running application 49 */ 50 UNSUPPORTED_APPLICATION: 14, 51 }); 52 53 export function errorString(errorCodeToLookup) { 54 for (let [errorName, errorCode] of Object.entries(ERRORS)) { 55 if (errorCode == errorCodeToLookup) { 56 return errorName; 57 } 58 } 59 return "UNDEFINED_ERROR"; 60 } 61 62 /** 63 * These are steps that the BackupService or any of its subcomponents might 64 * be going through during configuration, creation, deletion of or restoration 65 * from a backup. This is used to provide extra information to our error 66 * telemetry. 67 */ 68 export const STEPS = Object.freeze({ 69 /** 70 * This is the initial step upon creating a backup before any other steps 71 * begin. 72 */ 73 CREATE_BACKUP_ENTRYPOINT: 1, 74 75 /** 76 * Determine the final destination for the written archive. 77 */ 78 CREATE_BACKUP_RESOLVE_DESTINATION: 2, 79 80 /** 81 * Generate the manifest object for the backup. 82 */ 83 CREATE_BACKUP_CREATE_MANIFEST: 3, 84 85 /** 86 * Create the main `backups` working directory in the profile directory if it 87 * doesn't already exist. 88 */ 89 CREATE_BACKUP_CREATE_BACKUPS_FOLDER: 4, 90 91 /** 92 * Create the staging directory for the backup. 93 */ 94 CREATE_BACKUP_CREATE_STAGING_FOLDER: 5, 95 96 /** 97 * Attempt to load the encryption state if one exists. 98 */ 99 CREATE_BACKUP_LOAD_ENCSTATE: 6, 100 101 /** 102 * Run the backup routine for each BackupResource. 103 */ 104 CREATE_BACKUP_RUN_BACKUP: 7, 105 106 /** 107 * After populating with the data from each BackupResource, verify that 108 * the manifest adheres to the BackupManifest schema. 109 */ 110 CREATE_BACKUP_VERIFY_MANIFEST: 8, 111 112 /** 113 * Write the backup manifest to the staging directory. 114 */ 115 CREATE_BACKUP_WRITE_MANIFEST: 9, 116 117 /** 118 * Rename the staging directory with the time code, and clear out any 119 * expired directories. 120 */ 121 CREATE_BACKUP_FINALIZE_STAGING: 10, 122 123 /** 124 * Compress the staging directory into a single file. 125 */ 126 CREATE_BACKUP_COMPRESS_STAGING: 11, 127 128 /** 129 * Generate the single-file archive. 130 */ 131 CREATE_BACKUP_CREATE_ARCHIVE: 12, 132 133 /** 134 * Finalize the single-file archive and move it into the destination 135 * directory. 136 */ 137 CREATE_BACKUP_FINALIZE_ARCHIVE: 13, 138 });