The following usage of ScopedTempDir is wrong:
{
base::ScopedTempDir temp_dir;
base::FilePath path = temp_dir.path().AppendASCII("test.db");
// Write to |path|.
}
It needs to create the temp dir first:
{
base::ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
base::FilePath path = temp_dir.path().AppendASCII("test.db");
// Write to |path|.
}
However, the first version of the code will compile, will not emit any warnings (even in debug mode), and will likely work on most configurations, because ScopedTempDir::path() will return the empty path, which is likely valid.
In fact, when I did this mistake in https://codereview.chromium.org/2265103002/#ps20001, I almost landed the change, be it not for iOS simlator (all other platforms and even iOS device were fine with it).
I feel we should warn the programmer if they hold the scoped dir wrong.
Comment 1 by vabr@chromium.org
, Aug 24 2016