mirror of
				https://github.com/9001/copyparty.git
				synced 2025-11-04 05:43:17 +00:00 
			
		
		
		
	async lsof w/ timeout
This commit is contained in:
		@@ -1202,20 +1202,26 @@ def s3dec(rd: str, fn: str) -> tuple[str, str]:
 | 
				
			|||||||
    )
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def db_ex_chk(log: "NamedLogger", ex: Exception, db_path: str) -> None:
 | 
					def db_ex_chk(log: "NamedLogger", ex: Exception, db_path: str) -> bool:
 | 
				
			||||||
    if str(ex) != "database is locked":
 | 
					    if str(ex) != "database is locked":
 | 
				
			||||||
        return False
 | 
					        return False
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    try:
 | 
					    thr = threading.Thread(target=lsof, args=(log, db_path))
 | 
				
			||||||
        rc, so, se = runcmd([b"lsof", fsenc(db_path)])
 | 
					    thr.daemon = True
 | 
				
			||||||
        zs = (so.strip() + "\n" + se.strip()).strip()
 | 
					    thr.start()
 | 
				
			||||||
        log("lsof {} = {}\n{}".format(db_path, rc, zs), 3)
 | 
					 | 
				
			||||||
    except:
 | 
					 | 
				
			||||||
        pass
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return True
 | 
					    return True
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def lsof(log: "NamedLogger", abspath: str) -> None:
 | 
				
			||||||
 | 
					    try:
 | 
				
			||||||
 | 
					        rc, so, se = runcmd([b"lsof", b"-R", fsenc(abspath)], timeout=5)
 | 
				
			||||||
 | 
					        zs = (so.strip() + "\n" + se.strip()).strip()
 | 
				
			||||||
 | 
					        log("lsof {} = {}\n{}".format(abspath, rc, zs), 3)
 | 
				
			||||||
 | 
					    except:
 | 
				
			||||||
 | 
					        log("lsof failed; " + min_ex(), 3)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def atomic_move(usrc: str, udst: str) -> None:
 | 
					def atomic_move(usrc: str, udst: str) -> None:
 | 
				
			||||||
    src = fsenc(usrc)
 | 
					    src = fsenc(usrc)
 | 
				
			||||||
    dst = fsenc(udst)
 | 
					    dst = fsenc(udst)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user