{"record":{"id":"16c0d0ca682721dd","repo":"siyuan-note/siyuan","slug":"refuse-to-overwrite-existing-encrypted-notebook","errorCode":null,"errorMessage":"refuse to overwrite existing encrypted notebook [%s]","messagePattern":"refuse to overwrite existing encrypted notebook \\[(.+?)\\]","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/import.go","lineNumber":1383,"sourceCode":"\t\t\tboxCrypt = backup\n\t\t}\n\n\t\tpayloadFound, payloadErr := hasEncryptedNotebookPayloadAtPath(boxDir)\n\t\tif payloadErr != nil {\n\t\t\treturn nil, fmt.Errorf(\"inspect imported notebook [%s] failed: %w\", boxID, payloadErr)\n\t\t}\n\t\tif boxCrypt == nil && payloadFound {\n\t\t\treturn nil, fmt.Errorf(\"imported notebook [%s] contains encrypted payload without identity\", boxID)\n\t\t}\n\t\tif boxCrypt == nil {\n\t\t\tcontinue\n\t\t}\n\n\t\tif err = validateBoxEncryption(boxCrypt); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"invalid imported notebook identity [%s]: %w\", boxID, err)\n\t\t}\n\t\tif filelock.IsExist(filepath.Join(util.DataDir, boxID)) && IsEncryptedBox(boxID) {\n\t\t\treturn nil, fmt.Errorf(\"refuse to overwrite existing encrypted notebook [%s]\", boxID)\n\t\t}\n\t\tencryptedBoxIDs = append(encryptedBoxIDs, boxID)\n\t}\n\treturn encryptedBoxIDs, nil\n}\n\nfunc ImportData(zipPath string) (err error) {\n\tutil.PushEndlessProgress(Conf.Language(73))\n\tdefer util.ClearPushProgress(100)\n\n\tlockSync()\n\tdefer unlockSync()\n\n\tlogging.LogInfof(\"import data from [%s]\", zipPath)\n\tbaseName := filepath.Base(zipPath)\n\text := filepath.Ext(baseName)\n\tbaseName = strings.TrimSuffix(baseName, ext)\n\tunzipPath := filepath.Join(filepath.Dir(zipPath), baseName)","sourceCodeStart":1365,"sourceCodeEnd":1401,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/import.go#L1365-L1401","documentation":"During data.zip import, if a notebook ID in the archive matches an existing encrypted notebook already present in the target workspace, the import refuses to overwrite it. Overwriting would destroy existing encrypted data whose identity may differ from the imported one, making recovery impossible.","triggerScenarios":"ImportData with a data.zip containing a notebook whose ID equals an existing encrypted notebook ID in util.DataDir and IsEncryptedBox(boxID) is true for the existing notebook.","commonSituations":"Re-importing the same workspace backup twice; importing an old backup over a workspace where the same notebook was later re-created and encrypted with a different master key; restoring data.zip into a workspace that already synced that notebook.","solutions":["Rename or move the existing encrypted notebook out of the workspace (or change its ID) before importing","Delete the existing encrypted notebook intentionally if it is no longer needed, then re-run the import","Import into a fresh/empty workspace directory when the goal is a full restore","If both copies are needed, re-export one of them after giving it a different notebook ID"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Go: check for ID collisions with existing encrypted notebooks before import\nfor _, boxID := range zipNotebookIDs(zipPath) {\n    if filelock.IsExist(filepath.Join(util.DataDir, boxID)) && model.IsEncryptedBox(boxID) {\n        return fmt.Errorf(\"archive notebook %s collides with an existing encrypted notebook; rename or remove it first\", boxID)\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Restore data.zip backups into a clean workspace, not one that already contains the same notebooks","Rename/re-ID notebooks before re-exporting when both copies must coexist","Keep an inventory of notebook IDs used across backup archives","Never rely on import to merge over existing encrypted data"],"tags":["import","encryption","conflict","overwrite-protection"],"backgroundTag":"file-already-exists","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}