{"record":{"id":"dc9e6edd4755d3b9","repo":"siyuan-note/siyuan","slug":"cannot-create-a-file-starting-with","errorCode":null,"errorMessage":"Cannot create a file starting with .","messagePattern":"Cannot create a file starting with \\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/file.go","lineNumber":2264,"sourceCode":"\tif 512 < utf8.RuneCountInString(title) {\n\t\t// 限制笔记本名和文档名最大长度为 `512` https://github.com/siyuan-note/siyuan/issues/6299\n\t\treturn nil, errors.New(Conf.Language(106))\n\t}\n\n\tisEmpty := false\n\tif \"\" == title {\n\t\ttitle = Conf.Language(16)\n\t\tisEmpty = true\n\t} else if titleEmpty {\n\t\tisEmpty = true\n\t}\n\n\tbaseName := strings.TrimSpace(path.Base(p))\n\tif \"\" == util.GetTreeID(baseName) {\n\t\treturn nil, errors.New(Conf.Language(16))\n\t}\n\tif strings.HasPrefix(baseName, \".\") {\n\t\treturn nil, errors.New(Conf.Language(13))\n\t}\n\n\tbox, boxErr := getOpenedBox(boxID)\n\tif nil != boxErr {\n\t\treturn nil, boxErr\n\t}\n\n\tfolder := path.Dir(p)\n\thPath := \"/\" + title\n\tif \"/\" != folder {\n\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) {","sourceCodeStart":2246,"sourceCodeEnd":2282,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/251596fc0de2f9528c00c224252fd073a99973f4/kernel/model/file.go#L2246-L2282","documentation":"Thrown by validateCreateDoc when the path's base filename starts with a dot ('.'). Conf.Language(13) = 'Cannot create a file starting with .'. Dotfiles are hidden files on Unix and reserved names on Windows; SiYuan blocks them to prevent hidden document files, filesystem inconsistencies, and OS-level access issues.","triggerScenarios":"Calling create/validate functions with a path whose base name begins with '.', e.g., '/folder/.20240101-abcdefg.sy' or '/folder/.hidden.sy'. The check at line 2263 uses strings.HasPrefix(baseName, \".\").","commonSituations":"A path is constructed by prepending '.' accidentally (e.g., string concatenation bug). A template or migration generates dotfile-style paths. An imported file had a dot-prefixed name on the source filesystem.","solutions":["Strip any leading '.' from the path's base name before creating the document.","Ensure path construction logic doesn't prepend dots (common in template string bugs).","Pre-validate: check !strings.HasPrefix(path.Base(p), \".\") before calling create functions.","If a dotfile-named document was intended for hiding, use SiYuan's bookmark or hidden-bookmark IAL instead."],"exampleFix":"// before\np := \"/notes/.20240101120000-abcdefg.sy\"\nerr := model.ValidateCreateDoc(boxID, p, title)\n\n// after\nbase := path.Base(p)\nif strings.HasPrefix(base, \".\") {\n    base = strings.TrimPrefix(base, \".\")\n    p = path.Join(path.Dir(p), base)\n}\nerr := model.ValidateCreateDoc(boxID, p, title)","handlingStrategy":"validation","validationCode":"// Pre-check: ensure path base name doesn't start with a dot\nbaseName := strings.TrimSpace(path.Base(p))\nif strings.HasPrefix(baseName, \".\") {\n    baseName = strings.TrimPrefix(baseName, \".\")\n    p = path.Join(path.Dir(p), baseName)\n}","typeGuard":"func hasNoLeadingDot(p string) bool {\n    baseName := strings.TrimSpace(path.Base(p))\n    return !strings.HasPrefix(baseName, \".\")\n}","tryCatchPattern":null,"preventionTips":["Ensure path construction doesn't prepend dots to the base filename.","Check strings.HasPrefix(path.Base(p), \".\") before calling create functions.","Use SiYuan's bookmark/hidden IAL for hiding documents instead of dotfile names."],"tags":["create","validation","path","dotfile","filesystem"],"backgroundTag":null,"analyzedSha":"251596fc0de2f9528c00c224252fd073a99973f4","analyzedAt":"2026-08-12T21:18:37.123Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}