Skip to content

Files should be locked when writing to them #19

@JeremyTCD

Description

@JeremyTCD

Is the following:

//write the object payload (lock the file so we can write to it and force others to wait for us to finish)
using (FileStream stream = GetStream(cachedItemPath, FileMode.Create, FileAccess.Write))

Meant to have a true argument?

//write the object payload (lock the file so we can write to it and force others to wait for us to finish)
using (FileStream stream = GetStream(cachedItemPath, FileMode.Create, FileAccess.Write, true))

Correct me if i'm wrong, but at present, it seems like multiple threads/processes can write to a file at the same time. Additionally, if a thread attempts to read from the file while it is being written to, a partial read of the file can occur.

Same goes for:

//write the cache policy
using (FileStream stream = GetStream(cachedPolicy, FileMode.Create, FileAccess.Write))

Edit: Minor edits to phrasing

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