mirror of
				https://github.com/kovidgoyal/calibre.git
				synced 2025-11-04 03:27:00 -05:00 
			
		
		
		
	Edit book: Fix file permissions for the edited book being changed on Linux and OS X
Since the editor saves by using a temp file and then renaming the temp file to overwrite the original, we have to explicitly copy over permissions and owner metadata to the temp file to ensure they remain unchanged.
This commit is contained in:
		
							parent
							
								
									aea66db018
								
							
						
					
					
						commit
						f0d676502f
					
				@ -22,6 +22,13 @@ from calibre.utils.ipc import RC
 | 
			
		||||
def save_container(container, path):
 | 
			
		||||
    temp = PersistentTemporaryFile(
 | 
			
		||||
        prefix=('_' if iswindows else '.'), suffix=os.path.splitext(path)[1], dir=os.path.dirname(path))
 | 
			
		||||
    if hasattr(os, 'fchmod'):
 | 
			
		||||
        # Ensure file permissions and owner information is preserved
 | 
			
		||||
        fno = temp.fileno()
 | 
			
		||||
        st = os.stat(path)
 | 
			
		||||
        os.fchmod(fno, st.st_mode)
 | 
			
		||||
        os.fchown(fno, st.st_uid, st.st_gid)
 | 
			
		||||
 | 
			
		||||
    temp.close()
 | 
			
		||||
    temp = temp.name
 | 
			
		||||
    try:
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user