2022-08-26 15:44:59 +00:00
|
|
|
// Copyright 2014 Google LLC. All rights reserved.
|
2014-02-14 23:21:05 +00:00
|
|
|
//
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file or at
|
|
|
|
// https://developers.google.com/open-source/licenses/bsd
|
2013-11-12 20:37:58 +00:00
|
|
|
|
|
|
|
#ifndef MEDIA_FILE_FILE_CLOSER_H_
|
|
|
|
#define MEDIA_FILE_FILE_CLOSER_H_
|
|
|
|
|
2023-10-09 23:21:41 +00:00
|
|
|
#include <glog/logging.h>
|
2017-07-10 18:26:22 +00:00
|
|
|
#include "packager/file/file.h"
|
2013-11-12 20:37:58 +00:00
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
namespace shaka {
|
2013-11-12 20:37:58 +00:00
|
|
|
|
2016-08-17 17:41:40 +00:00
|
|
|
/// Used by std::unique_ptr to automatically close the file when it goes out of
|
2014-01-24 00:26:00 +00:00
|
|
|
/// scope.
|
2013-11-12 20:37:58 +00:00
|
|
|
struct FileCloser {
|
|
|
|
inline void operator()(File* file) const {
|
2015-11-12 23:56:23 +00:00
|
|
|
if (file != NULL) {
|
|
|
|
const std::string filename = file->file_name();
|
|
|
|
if (!file->Close()) {
|
2017-07-10 18:26:22 +00:00
|
|
|
LOG(WARNING) << "Failed to close the file properly: " << filename;
|
2015-11-12 23:56:23 +00:00
|
|
|
}
|
2013-11-12 20:37:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
} // namespace shaka
|
2013-11-12 20:37:58 +00:00
|
|
|
|
|
|
|
#endif // MEDIA_FILE_FILE_CLOSER_H_
|