Ensure config directory is created.
This commit is contained in:
		
							parent
							
								
									56c843cfc1
								
							
						
					
					
						commit
						7a4fc3491a
					
				
							
								
								
									
										16
									
								
								config.go
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								config.go
									
									
									
									
									
								
							@ -112,6 +112,14 @@ func ConfigPath() (fileDir, fileName string) {
 | 
			
		||||
	if flags.ConfigPath != "" {
 | 
			
		||||
		fileDir, fileName = filepath.Split(flags.ConfigPath)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Verify directory exists.
 | 
			
		||||
	if _, ferr := os.Stat(fileDir); ferr != nil {
 | 
			
		||||
		err := os.MkdirAll(fileDir, 0755)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			log.Error("Failed to make directory:", err)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -481,14 +489,6 @@ func SaveConfig() error {
 | 
			
		||||
	// Find the file name.
 | 
			
		||||
	fileDir, fileName := ConfigPath()
 | 
			
		||||
 | 
			
		||||
	// Verify directory exists.
 | 
			
		||||
	if _, ferr := os.Stat(fileDir); ferr != nil {
 | 
			
		||||
		err = os.MkdirAll(fileDir, 0755)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			log.Error("Failed to make directory:", err)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Write the configuration file.
 | 
			
		||||
	err = os.WriteFile(filepath.Join(fileDir, fileName), data, 0644)
 | 
			
		||||
	return err
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user