INNER CODE UNIT · Python

_should_reopen_file

lebinh/ngxtop · ngxtop/ngxtop.py:178

def _should_reopen_file(file_path, current_inode, current_size):
    """
    Check if file should be reopened due to rotation.
    Returns True if file has been rotated (inode changed or size decreased significantly).
    """
    try:
        file_stat = os.stat(file_path)
        new_inode = file_stat.st_ino
        new_size = file_stat.st_size
        
        # File has been rotated if:
        # 1. Inode changed (file was moved/renamed)
        # 2. File size decreased significantly (> 1000 bytes, indicating truncation/rotation)
        if current_inode is not None and new_inode != current_inode:
            return True
        
        if new_size < current_size - 1000:  # Allow for some buffer, but detect major size drops
            return True

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…