Skip to content

It doesn't work in Windows, or I don't understand it's logic #115

@jumperrg

Description

@jumperrg

I'm able to write to a file despite the library is working. Here is my "locking" code:


const file = './file.txt';

function delay(ms) {
    return new Promise(resolve => setTimeout(resolve, ms));
}

// === main logic ===
lockfile.lock(file)
.then(async (release) => {

    await delay(10000);

    return release();
})
.catch((e) => {
    console.error(e)
});

It locks the file.txt for 10 seconds, and during this time I shouldn't be able to write the file from other processes(if I understand it correctly), but I can open the file in windows "notepad" and change the text.

Here is the code I run in parallel, and it also does rewrite the file.txt :


(() => {
    try {
        const fd = fs.openSync('./file.txt', 'a+');
        fs.writeFileSync(fd, 'some nasty text')
    } catch (e) {
        console.error(e);
    }
})();

So, what does the lib do?
Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions