This is an archive of the discontinued LLVM Phabricator instance.

Create a TempFile class
ClosedPublic

Authored by rafael on Nov 10 2017, 1:43 PM.

Details

Reviewers
rnk
ruiu
Summary

This just adds a TempFile class and replaces the use in FileOutputBuffer with it.

The only difference for now is better error handling. My idea is to once this is in:

  • Convert other user of temporary files to it.
  • Add support for automatically deleting on windows.
  • Add a createUnnamed method that returns a potentially unnamed file. It would be actually unnamed on modern linux and have a unknown name on windows.

Diff Detail

Event Timeline

rafael created this revision.Nov 10 2017, 1:43 PM
rnk added inline comments.Nov 10 2017, 2:46 PM
include/llvm/Support/FileSystem.h
698

Some basic Doxygen here would be good.

703

Basic doxygen, probably just referring the reader to createUniqueFile.

711

= -1, just in case we forget to initialize FD one day.

lib/Support/Path.cpp
770

Should this attempt to discard the file if it wasn't committed? Otherwise users may need to invent RAII things like:

DiscardingTempFile : TempFile {
  ~DiscardingTempFile() { if (!Done) consumeError(discard()); }
};

I guess if we leave it this way, users are discouraged from doing that.

Add comments.

rnk accepted this revision.Nov 11 2017, 6:47 AM

Looks good

This revision is now accepted and ready to land.Nov 11 2017, 6:47 AM
ruiu added inline comments.Nov 12 2017, 9:13 PM
lib/Support/Path.cpp
773–774

I think that calling keep or Done more than once on an object should be an error because I can't think of a use case in which allowing it is useful.

rafael closed this revision.Nov 13 2017, 10:35 AM

r318069 .