Compare commits
	
		
			No commits in common. "createdirs-uid" and "master" have entirely different histories.
		
	
	
		
			createdirs
			...
			master
		
	
		
					 1 changed files with 8 additions and 2 deletions
				
			
		| 
						 | 
				
			
			@ -4,6 +4,8 @@ Create required Onionr directories
 | 
			
		|||
"""
 | 
			
		||||
import os
 | 
			
		||||
import stat
 | 
			
		||||
from pwd import getpwuid
 | 
			
		||||
from getpass import getuser
 | 
			
		||||
 | 
			
		||||
from . import identifyhome
 | 
			
		||||
import filepaths
 | 
			
		||||
| 
						 | 
				
			
			@ -25,6 +27,10 @@ import onionrexceptions
 | 
			
		|||
home = identifyhome.identify_home()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def find_owner(filename):
 | 
			
		||||
    return getpwuid(os.stat(filename).st_uid).pw_name
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def create_dirs():
 | 
			
		||||
    """Create onionr data-related directories in
 | 
			
		||||
    order of the hardcoded list below,
 | 
			
		||||
| 
						 | 
				
			
			@ -35,7 +41,7 @@ def create_dirs():
 | 
			
		|||
        if not os.path.exists(path):
 | 
			
		||||
            os.makedirs(path)
 | 
			
		||||
        else:
 | 
			
		||||
            if os.getuid() != os.stat(path).st_uid:
 | 
			
		||||
            if getuser() != find_owner(path):
 | 
			
		||||
                raise onionrexceptions.InsecureDirectoryUsage(
 | 
			
		||||
                    "Directory " + path +
 | 
			
		||||
                    " already exists and is not owned by the same user")
 | 
			
		||||
| 
						 | 
				
			
			@ -48,4 +54,4 @@ def create_dirs():
 | 
			
		|||
        try:
 | 
			
		||||
            db()
 | 
			
		||||
        except FileExistsError:
 | 
			
		||||
            pass
 | 
			
		||||
            pass
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue