{"record":{"id":"a0987af131a39336","repo":"siyuan-note/siyuan","slug":"duplicated-filename","errorCode":null,"errorMessage":"Duplicated filename","messagePattern":"Duplicated filename","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"kernel/model/file.go","lineNumber":2293,"sourceCode":"\t\tparentID := path.Base(folder)\n\t\tparentTree, loadErr := LoadTreeByBlockID(parentID)\n\t\tif nil != loadErr {\n\t\t\tlogging.LogErrorf(\"get parent tree [%s] failed\", parentID)\n\t\t\treturn nil, ErrBlockNotFound\n\t\t}\n\t\tparentPath := strings.TrimSuffix(parentTree.Path, \".sy\")\n\t\tif parentTree.Box != boxID || cleanBoxDocDir(parentPath) != cleanBoxDocDir(folder) {\n\t\t\tlogging.LogErrorf(\"parent tree [%s] does not match box [%s] and folder [%s]\", parentID, boxID, folder)\n\t\t\treturn nil, ErrBlockNotFound\n\t\t}\n\t\thPath = path.Join(parentTree.HPath, title)\n\t}\n\n\tif depth := strings.Count(p, \"/\"); 7 < depth && !Conf.FileTree.AllowCreateDeeper {\n\t\treturn nil, errors.New(Conf.Language(118))\n\t}\n\tif box.Exist(p) {\n\t\treturn nil, errors.New(Conf.Language(1))\n\t}\n\n\tret = &createDocValidation{\n\t\tbox:     box,\n\t\tpath:    p,\n\t\ttitle:   title,\n\t\thPath:   hPath,\n\t\tid:      util.GetTreeID(p),\n\t\tfolder:  folder,\n\t\tisEmpty: isEmpty,\n\t}\n\treturn\n}\n\nfunc cleanBoxDocDir(p string) string {\n\treturn path.Clean(\"/\" + strings.TrimPrefix(p, \"/\"))\n}\n","sourceCodeStart":2275,"sourceCodeEnd":2311,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/251596fc0de2f9528c00c224252fd073a99973f4/kernel/model/file.go#L2275-L2311","documentation":"Thrown by validateCreateDoc when a document already exists at the given path. Conf.Language(1) = 'Duplicated filename'. The check uses box.Exist(p) which tests for the presence of a .sy file at that path. This is the final validation before the function returns success, after all other checks (title length, ID validity, dotfile, depth) have passed.","triggerScenarios":"Calling create/validate functions with a path where a .sy file already exists. Common when the caller reuses an existing document ID/path, or when a concurrent create operation races to create the same path.","commonSituations":"A create-with-ID call uses an ID that already exists (duplicate ID generation or collision). A retry of a previously successful create. A concurrent batch create where two items resolve to the same path. A UI 'create document here' action where a document with the same generated ID already exists.","solutions":["Generate a new unique ID for the document path if one already exists.","Check box.Exist(p) before calling create functions and generate an alternative path if it returns true.","For retry logic, verify the document wasn't already created before re-attempting.","In concurrent scenarios, use the createDocLock (already held by CreateWithMarkdown) or coordinate ID generation to avoid collisions."],"exampleFix":"// before\nerr := model.ValidateCreateDoc(boxID, p, title)\n\n// after\nbox := conf.Box(boxID)\nif box != nil && box.Exist(p) {\n    // generate a new unique ID/path\n    newID := util.NewNodeID()\n    p = path.Join(path.Dir(p), newID+\".sy\")\n}\nerr := model.ValidateCreateDoc(boxID, p, title)","handlingStrategy":"validation","validationCode":"// Pre-check: ensure no document exists at the target path\nbox := conf.Box(boxID)\nif box != nil && box.Exist(p) {\n    // generate a new unique ID/path\n    newID := util.NewNodeID()\n    p = path.Join(path.Dir(p), newID+\".sy\")\n}","typeGuard":"func pathIsAvailable(boxID, p string) bool {\n    box := conf.Box(boxID)\n    if box == nil {\n        return false\n    }\n    return !box.Exist(p)\n}","tryCatchPattern":null,"preventionTips":["Check box.Exist(p) before calling create functions and generate an alternative path if occupied.","Generate fresh unique IDs for each document to avoid path collisions.","For retry logic, verify the document wasn't already created before re-attempting.","In concurrent scenarios, rely on createDocLock to serialize ID generation."],"tags":["create","validation","duplicate","path","existence-check"],"backgroundTag":null,"analyzedSha":"251596fc0de2f9528c00c224252fd073a99973f4","analyzedAt":"2026-08-12T21:18:37.123Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}