@@ -274,3 +274,99 @@ def test_unmonitored_mounted_dir(
274274 )
275275
276276 server .wait_events ([event ])
277+
278+
279+ def test_open_via_hardlink (monitored_dir , server ):
280+ """
281+ Tests opening a file through a hardlink path when the original exists.
282+ The event should report the hardlink path as host_path.
283+
284+ Args:
285+ monitored_dir: Temporary directory path for creating test files.
286+ server: The server instance to communicate with.
287+ """
288+ process = Process .from_proc ()
289+
290+ # Create original file
291+ original = os .path .join (monitored_dir , 'original.txt' )
292+ with open (original , 'w' ) as f :
293+ f .write ('test content' )
294+
295+ # Create hardlink
296+ hardlink = os .path .join (monitored_dir , 'hardlink.txt' )
297+ os .link (original , hardlink )
298+
299+ # Open through hardlink
300+ with open (hardlink , 'r' ) as f :
301+ f .read ()
302+
303+ events = [
304+ Event (
305+ process = process ,
306+ event_type = EventType .CREATION ,
307+ file = original ,
308+ host_path = original ,
309+ ),
310+ Event (
311+ process = process ,
312+ event_type = EventType .CREATION ,
313+ file = hardlink ,
314+ host_path = hardlink ,
315+ ),
316+ Event (
317+ process = process ,
318+ event_type = EventType .OPEN ,
319+ file = hardlink ,
320+ host_path = hardlink ,
321+ ),
322+ ]
323+
324+ server .wait_events (events )
325+
326+
327+ def test_open_via_original_with_hardlink (monitored_dir , server ):
328+ """
329+ Tests opening a file through its original path when a hardlink exists.
330+ Both paths should be tracked for the same inode.
331+
332+ Args:
333+ monitored_dir: Temporary directory path for creating test files.
334+ server: The server instance to communicate with.
335+ """
336+ process = Process .from_proc ()
337+
338+ # Create original file
339+ original = os .path .join (monitored_dir , 'original.txt' )
340+ with open (original , 'w' ) as f :
341+ f .write ('test content' )
342+
343+ # Create hardlink
344+ hardlink = os .path .join (monitored_dir , 'hardlink.txt' )
345+ os .link (original , hardlink )
346+
347+ # Open through original path
348+ with open (original , 'r' ) as f :
349+ f .read ()
350+
351+ events = [
352+ Event (
353+ process = process ,
354+ event_type = EventType .CREATION ,
355+ file = original ,
356+ host_path = original ,
357+ ),
358+ Event (
359+ process = process ,
360+ event_type = EventType .CREATION ,
361+ file = hardlink ,
362+ host_path = hardlink ,
363+ ),
364+ Event (
365+ process = process ,
366+ event_type = EventType .OPEN ,
367+ file = original ,
368+ host_path = original ,
369+ ),
370+ ]
371+
372+ server .wait_events (events )
0 commit comments