X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2FFile.cpp;h=6c2d550e0b3a4702c86a7cfe3ffd68fe4c1a5603;hb=06fe0874f2c3a786c79695e5b20c5f4580e05115;hp=2f239c2ace035c7a1c8f8845b1f68debbcb7a211;hpb=75c6adfae4a1842511e8b62150cc18ffb391efa7;p=folly.git diff --git a/folly/File.cpp b/folly/File.cpp index 2f239c2a..6c2d550e 100644 --- a/folly/File.cpp +++ b/folly/File.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2014 Facebook, Inc. + * Copyright 2016 Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,6 +18,7 @@ #include #include +#include #include #include @@ -52,6 +53,12 @@ File::File(const char* name, int flags, mode_t mode) ownsFd_ = true; } +File::File(const std::string& name, int flags, mode_t mode) + : File(name.c_str(), flags, mode) {} + +File::File(StringPiece name, int flags, mode_t mode) + : File(name.str(), flags, mode) {} + File::File(File&& other) noexcept : fd_(other.fd_) , ownsFd_(other.ownsFd_) { @@ -65,7 +72,11 @@ File& File::operator=(File&& other) { } File::~File() { - closeNoThrow(); // ignore error + auto fd = fd_; + if (!closeNoThrow()) { // ignore most errors + DCHECK_NE(errno, EBADF) << "closing fd " << fd << ", it may already " + << "have been closed. Another time, this might close the wrong FD."; + } } /* static */ File File::temporary() {