isLockActive function

bool isLockActive(
  1. String lockFilePath
)

Check if a lock file represents an active lock (process still running).

Implementation

bool isLockActive(String lockFilePath) {
  final content = readLockContent(lockFilePath);
  if (content == null) return false;

  if (!isProcessRunning(content.pid)) return false;
  if (!_isNeomageProcess(content.pid, content.execPath)) return false;

  // Fallback: if the lock is very old (> 2 hours), double-check
  try {
    final stat = File(lockFilePath).statSync();
    final age =
        DateTime.now().millisecondsSinceEpoch -
        stat.modified.millisecondsSinceEpoch;
    if (age > fallbackStaleMs) {
      if (!isProcessRunning(content.pid)) return false;
    }
  } catch (_) {
    // Trust the PID check
  }

  return true;
}