mirror of
				https://github.com/Garmelon/PFERD.git
				synced 2025-11-04 14:42:49 +01:00 
			
		
		
		
	Update file metadata in more cases
PFERD now not only updates file metadata when a file is successfully added or changed, but also when a file is downloaded and then detected to be unchanged. This could occur for example if a remote file's modification time was bumped, possibly because somebody touched the file without changing it.
This commit is contained in:
		@@ -303,6 +303,11 @@ class OutputDirectory:
 | 
			
		||||
 | 
			
		||||
        return None
 | 
			
		||||
 | 
			
		||||
    def _update_metadata(self, info: DownloadInfo) -> None:
 | 
			
		||||
        if mtime := info.heuristics.mtime:
 | 
			
		||||
            mtimestamp = mtime.timestamp()
 | 
			
		||||
            os.utime(info.local_path, times=(mtimestamp, mtimestamp))
 | 
			
		||||
 | 
			
		||||
    async def _after_download(self, info: DownloadInfo) -> None:
 | 
			
		||||
        changed = False
 | 
			
		||||
 | 
			
		||||
@@ -314,6 +319,7 @@ class OutputDirectory:
 | 
			
		||||
        if info.local_path.exists():
 | 
			
		||||
            changed = True
 | 
			
		||||
            if filecmp.cmp(info.local_path, info.tmp_path):
 | 
			
		||||
                self._update_metadata(info)
 | 
			
		||||
                info.tmp_path.unlink()
 | 
			
		||||
                return
 | 
			
		||||
 | 
			
		||||
@@ -321,15 +327,8 @@ class OutputDirectory:
 | 
			
		||||
                info.tmp_path.unlink()
 | 
			
		||||
                return
 | 
			
		||||
 | 
			
		||||
        # Modify metadata if necessary
 | 
			
		||||
        if mtime := info.heuristics.mtime:
 | 
			
		||||
            # TODO Pick an implementation
 | 
			
		||||
            # Rounding up to avoid inaccuracies in how the OS stores timestamps
 | 
			
		||||
            # mtimestamp = math.ceil(mtime.timestamp())
 | 
			
		||||
            mtimestamp = mtime.timestamp()
 | 
			
		||||
            os.utime(info.tmp_path, times=(mtimestamp, mtimestamp))
 | 
			
		||||
 | 
			
		||||
        info.tmp_path.replace(info.local_path)
 | 
			
		||||
        self._update_metadata(info)
 | 
			
		||||
 | 
			
		||||
        if changed:
 | 
			
		||||
            self._conductor.print(
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user