@@ -37,8 +37,9 @@ type Profile struct {
3737func checkDataDir (dataDir string ) (string , error ) {
3838 // Convert to absolute path if relative path is supplied.
3939 if ! filepath .IsAbs (dataDir ) {
40- relativeDir := filepath .Join (filepath .Dir (os .Args [0 ]), dataDir )
41- absDir , err := filepath .Abs (relativeDir )
40+ // Use current working directory, not the binary's directory
41+ // This ensures we use the actual working directory where the process runs
42+ absDir , err := filepath .Abs (dataDir )
4243 if err != nil {
4344 return "" , err
4445 }
@@ -56,23 +57,24 @@ func checkDataDir(dataDir string) (string, error) {
5657func (p * Profile ) Validate () error {
5758 // Set default data directory if not specified
5859 if p .Data == "" {
59- if p .Demo {
60- // In demo mode, use current directory
61- p .Data = "."
60+ if runtime .GOOS == "windows" {
61+ p .Data = filepath .Join (os .Getenv ("ProgramData" ), "memos" )
6262 } else {
63- // In production mode, use system directory
64- if runtime .GOOS == "windows" {
65- p .Data = filepath .Join (os .Getenv ("ProgramData" ), "memos" )
66- } else {
67- // On Linux/macOS, check if /var/opt/memos exists (Docker scenario)
68- // If not, fall back to current directory to avoid permission issues
69- if _ , err := os .Stat ("/var/opt/memos" ); err == nil {
63+ // On Linux/macOS, check if /var/opt/memos exists and is writable (Docker scenario)
64+ if info , err := os .Stat ("/var/opt/memos" ); err == nil && info .IsDir () {
65+ // Check if we can write to this directory
66+ testFile := filepath .Join ("/var/opt/memos" , ".write-test" )
67+ if err := os .WriteFile (testFile , []byte ("test" ), 0600 ); err == nil {
68+ os .Remove (testFile )
7069 p .Data = "/var/opt/memos"
7170 } else {
72- slog . Warn ( "default production data directory /var/opt/memos not accessible, using current directory. " +
73- "Consider using --data flag to specify a data directory. " )
71+ // /var/opt/memos exists but is not writable, use current directory
72+ slog . Warn ( "/var/opt/memos is not writable, using current directory" )
7473 p .Data = "."
7574 }
75+ } else {
76+ // /var/opt/memos doesn't exist, use current directory (local development)
77+ p .Data = "."
7678 }
7779 }
7880 }
0 commit comments