Skip to main content
added syntax-highlighting
Source Link
Deduplicator
  • 9.1k
  • 5
  • 33
  • 52

For this particular case, the answer is easy enough...

There is a race condition between FileExists and OpenFile: what happens if the file is removed?

The only sane way to deal with this particular case is to skip FileExists:

contents = OpenFile(file);
if (!contents) // open failed
    DefaultAction();
else (SomeTest(contents))
    DoSomething(contents);
contents = OpenFile(file);
if (!contents) // open failed
    DefaultAction();
else (SomeTest(contents))
    DoSomething(contents);

This neatly solves this problem and makes the code cleaner.

In general: Try to rethink the problem and devise another solution which avoids the issue entirely.

For this particular case, the answer is easy enough...

There is a race condition between FileExists and OpenFile: what happens if the file is removed?

The only sane way to deal with this particular case is to skip FileExists:

contents = OpenFile(file);
if (!contents) // open failed
    DefaultAction();
else (SomeTest(contents))
    DoSomething(contents);

This neatly solves this problem and makes the code cleaner.

In general: Try to rethink the problem and devise another solution which avoids the issue entirely.

For this particular case, the answer is easy enough...

There is a race condition between FileExists and OpenFile: what happens if the file is removed?

The only sane way to deal with this particular case is to skip FileExists:

contents = OpenFile(file);
if (!contents) // open failed
    DefaultAction();
else (SomeTest(contents))
    DoSomething(contents);

This neatly solves this problem and makes the code cleaner.

In general: Try to rethink the problem and devise another solution which avoids the issue entirely.

added 7 characters in body
Source Link
Martin Wickman
  • 13.4k
  • 3
  • 33
  • 66

For this particular case, the answer is easy enough...

There is a race condition between FileExists and OpenFile: what happens if the file is removed during that time?

The only sane way to deal with this particular case is to skip FileExists, like this:

contents = OpenFile(file);
if (!contents) // open failed
    DefaultAction();
else (SomeTest(contents))
    DoSomething(contents);

This neatly solves this problem and makes the code cleaner.

In general: RethinkTry to rethink the problem and come up with a cleanerdevise another solution which avoids the issue entirely.

For this particular case, the answer is easy enough.

There is a race condition between FileExists and OpenFile: what happens if the file is removed during that time?

The only sane way to deal with this particular case is to skip FileExists, like this:

contents = OpenFile(file);
if (!contents) // failed
    DefaultAction();
else (SomeTest(contents))
    DoSomething(contents);

This neatly solves this problem.

In general: Rethink the problem and come up with a cleaner solution which avoids the issue entirely.

For this particular case, the answer is easy enough...

There is a race condition between FileExists and OpenFile: what happens if the file is removed?

The only sane way to deal with this particular case is to skip FileExists:

contents = OpenFile(file);
if (!contents) // open failed
    DefaultAction();
else (SomeTest(contents))
    DoSomething(contents);

This neatly solves this problem and makes the code cleaner.

In general: Try to rethink the problem and devise another solution which avoids the issue entirely.

Source Link
Martin Wickman
  • 13.4k
  • 3
  • 33
  • 66

For this particular case, the answer is easy enough.

There is a race condition between FileExists and OpenFile: what happens if the file is removed during that time?

The only sane way to deal with this particular case is to skip FileExists, like this:

contents = OpenFile(file);
if (!contents) // failed
    DefaultAction();
else (SomeTest(contents))
    DoSomething(contents);

This neatly solves this problem.

In general: Rethink the problem and come up with a cleaner solution which avoids the issue entirely.

Post Made Community Wiki by Martin Wickman