mirror of
				https://github.com/moby/moby.git
				synced 2022-11-09 12:21:53 -05:00 
			
		
		
		
	Safer file io for configuration files
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
		
							parent
							
								
									6f67c13d20
								
							
						
					
					
						commit
						ea3cbd3274
					
				
					 7 changed files with 119 additions and 38 deletions
				
			
		| 
						 | 
				
			
			@ -5,6 +5,8 @@ import (
 | 
			
		|||
	"os"
 | 
			
		||||
	"path/filepath"
 | 
			
		||||
	"sync"
 | 
			
		||||
 | 
			
		||||
	"github.com/docker/docker/pkg/ioutils"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// Store implements a K/V store for mapping distribution-related IDs
 | 
			
		||||
| 
						 | 
				
			
			@ -56,14 +58,10 @@ func (store *FSMetadataStore) Set(namespace, key string, value []byte) error {
 | 
			
		|||
	defer store.Unlock()
 | 
			
		||||
 | 
			
		||||
	path := store.path(namespace, key)
 | 
			
		||||
	tempFilePath := path + ".tmp"
 | 
			
		||||
	if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	if err := ioutil.WriteFile(tempFilePath, value, 0644); err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	return os.Rename(tempFilePath, path)
 | 
			
		||||
	return ioutils.AtomicWriteFile(path, value, 0644)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Delete removes data indexed by namespace and key. The data file named after
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue