Bump version to 47:0
[folly.git] / folly / File.cpp
index 12c4902f05cb553587d285b7118ca43f80f49aa9..379efe62eb0c650c5d06b82650635594240f4e1d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2014 Facebook, Inc.
+ * Copyright 2015 Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -52,7 +52,7 @@ File::File(const char* name, int flags, mode_t mode)
   ownsFd_ = true;
 }
 
-File::File(File&& other)
+File::File(File&& other) noexcept
   : fd_(other.fd_)
   , ownsFd_(other.ownsFd_) {
   other.release();
@@ -65,7 +65,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() {
@@ -80,7 +84,7 @@ File::~File() {
   return File(fd, true);
 }
 
-int File::release() {
+int File::release() noexcept {
   int released = fd_;
   fd_ = -1;
   ownsFd_ = false;