Skip to content

get unexpected 'unlinkdir' event,it should be 'unlink' #1421

@coderall2

Description

@coderall2

Describe the bug

A clear and concise description of what the bug is.

Versions (please complete the following information):

  • Chokidar version: 4.0.3
  • Node version: v16.20
  • OS version: Windows 10

To Reproduce:

my code like this:

import { setTimeout } from 'node:timers/promises';
import { FSWatcher } from './index.js';
import * as fs from 'fs';
import * as sp from 'node:path';
const util = require('node:util');
import { writeFileSync } from "fs";

const myWatcher = new FSWatcher({
alwaysStat: true,
awaitWriteFinish: {
stabilityThreshold: 1000,
pollInterval: 1000,
},
ignored: /(..part$)|(..lnk$)|(.*.tmp$)/,
followSymlinks: false,
atomic: 2000,
ignoreInitial: true,
});

let event_array: any[] = []
let root_watch_dir: string = 'E:\my_chokidar\test'
myWatcher.add(root_watch_dir)
myWatcher.on('all', (eventName, path, stat) => {

var file_path = path
var event_name = eventName.toLowerCase()
if (stat) {
var json: Record<string, any> = { "name": file_path, "action": event_name, 'event_time': stat.mtimeMs * 1000 }
event_array.push(json)
} else {
var json: Record<string, any> = { "name": file_path, "action": event_name, 'event_time': 0 }
event_array.push(json)
}
});

I record the event watch by chokidar and store them into event_array. Then i write 1000*4M file in backgroup thread and unlink them after thread exit. What event i expect to catch is 'add' 'change' and 'unlink', but i got some 'unlinkdir' which acually not a dir at all

Image

my backgroup thread code like this:

def create_new_file_in_dir(dir, num, init_file_content = False, init_file_size = 0):

start_time = get_current_time_in_us()

result = []
verify_dir_info(dir)
for i in range(0, num):
    new_file_name = '%s_%s' % (NEW_FILE_NAME, i)
    new_file_path = os.path.join(dir, new_file_name)
    file_dict = {}
    file_fd = open(new_file_path, 'x')
    if init_file_content:
        content = init_file_size * 'a'
        file_fd.write(content)
    file_fd.close()
    event_object = gen_event_object(new_file_path, 'add')
    result.append(event_object)

    try_to_sleep(i)

end_time = get_current_time_in_us()

print('create %d files cost:%d(us)' % (num, end_time - start_time))
return result

It didn't call mkdir at all

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions