diff --git a/app/server/modules/repositories/repositories.service.ts b/app/server/modules/repositories/repositories.service.ts index 887fc018..2b68d351 100644 --- a/app/server/modules/repositories/repositories.service.ts +++ b/app/server/modules/repositories/repositories.service.ts @@ -25,14 +25,14 @@ const encryptConfig = async (config: RepositoryConfig): Promise true) + .catch(() => false); + + if (repoExists && !config.isExistingRepository) { + throw new ConflictError( + `A restic repository already exists at this location. ` + + `If you want to use the existing repository, set "isExistingRepository": true in the config.` + ); + } + + if (!repoExists && config.isExistingRepository) { + throw new InternalServerError( + `Cannot access existing repository. Verify the path/credentials are correct and the repository exists.` + ); + } + const [created] = await db .insert(repositoriesTable) .values({ @@ -104,27 +122,9 @@ const createRepository = async (name: string, config: RepositoryConfig, compress let error: string | null = null; - if (config.isExistingRepository) { - const result = await restic - .snapshots(encryptedConfig) - .then(() => ({ error: null })) - .catch((err) => ({ error: err })); - - error = result.error; - } else { + if (!repoExists) { const initResult = await restic.init(encryptedConfig); error = initResult.error; - - if (error) { - const errorStr = typeof error === "string" ? error : (error as Error)?.message || ""; - if (errorStr.includes("config file already exists")) { - const verifyResult = await restic - .snapshots(encryptedConfig) - .then(() => ({ error: null })) - .catch((err) => ({ error: err })); - error = verifyResult.error; - } - } } if (!error) {