mirror of
				https://github.com/wting/autojump
				synced 2025-06-13 12:54:07 +00:00 
			
		
		
		
	Creates data directory before attempting to save the database.
Fixes #218.
This commit is contained in:
		
							parent
							
								
									986f02124e
								
							
						
					
					
						commit
						0b25bef134
					
				
							
								
								
									
										19
									
								
								bin/autojump
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								bin/autojump
									
									
									
									
									
								
							@ -23,6 +23,7 @@ from __future__ import division, print_function
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import collections
 | 
					import collections
 | 
				
			||||||
import difflib
 | 
					import difflib
 | 
				
			||||||
 | 
					import errno
 | 
				
			||||||
import math
 | 
					import math
 | 
				
			||||||
import operator
 | 
					import operator
 | 
				
			||||||
import os
 | 
					import os
 | 
				
			||||||
@ -31,6 +32,7 @@ import shutil
 | 
				
			|||||||
import sys
 | 
					import sys
 | 
				
			||||||
import tempfile
 | 
					import tempfile
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
try:
 | 
					try:
 | 
				
			||||||
    import argparse
 | 
					    import argparse
 | 
				
			||||||
except ImportError:
 | 
					except ImportError:
 | 
				
			||||||
@ -39,6 +41,15 @@ except ImportError:
 | 
				
			|||||||
    import autojump_argparse as argparse
 | 
					    import autojump_argparse as argparse
 | 
				
			||||||
    sys.path.pop()
 | 
					    sys.path.pop()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def create_dir_atomically(path):
 | 
				
			||||||
 | 
					    try:
 | 
				
			||||||
 | 
					        os.makedirs(path)
 | 
				
			||||||
 | 
					    except OSError as exception:
 | 
				
			||||||
 | 
					        if exception.errno != errno.EEXIST:
 | 
				
			||||||
 | 
					            raise
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Database:
 | 
					class Database:
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    Abstraction for interfacing with with autojump database file.
 | 
					    Abstraction for interfacing with with autojump database file.
 | 
				
			||||||
@ -96,7 +107,11 @@ class Database:
 | 
				
			|||||||
        if ((not os.path.exists(self.filename)) or
 | 
					        if ((not os.path.exists(self.filename)) or
 | 
				
			||||||
                os.name == 'nt' or
 | 
					                os.name == 'nt' or
 | 
				
			||||||
                os.getuid() == os.stat(self.filename)[4]):
 | 
					                os.getuid() == os.stat(self.filename)[4]):
 | 
				
			||||||
            temp = tempfile.NamedTemporaryFile(dir=self.config['data'],
 | 
					
 | 
				
			||||||
 | 
					            create_dir_atomically(self.config['data'])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            temp = tempfile.NamedTemporaryFile(
 | 
				
			||||||
 | 
					                    dir=self.config['data'],
 | 
				
			||||||
                    delete=False)
 | 
					                    delete=False)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            for path, weight in sorted(self.data.items(),
 | 
					            for path, weight in sorted(self.data.items(),
 | 
				
			||||||
@ -196,7 +211,7 @@ class Database:
 | 
				
			|||||||
def set_defaults():
 | 
					def set_defaults():
 | 
				
			||||||
    config = {}
 | 
					    config = {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    config['version'] = 'release-v21.7.0'
 | 
					    config['version'] = 'release-v21.7.1'
 | 
				
			||||||
    config['max_paths'] = 1000
 | 
					    config['max_paths'] = 1000
 | 
				
			||||||
    config['separator'] = '__'
 | 
					    config['separator'] = '__'
 | 
				
			||||||
    config['home'] = os.path.expanduser('~')
 | 
					    config['home'] = os.path.expanduser('~')
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user