| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium OS Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_FILE_WRITER_H__ | 5 #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_FILE_WRITER_H__ |
| 6 #define CHROMEOS_PLATFORM_UPDATE_ENGINE_FILE_WRITER_H__ | 6 #define CHROMEOS_PLATFORM_UPDATE_ENGINE_FILE_WRITER_H__ |
| 7 | 7 |
| 8 #include <sys/types.h> | 8 #include <sys/types.h> |
| 9 #include <sys/stat.h> | 9 #include <sys/stat.h> |
| 10 #include <fcntl.h> | 10 #include <fcntl.h> |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 virtual ~DirectFileWriter() {} | 47 virtual ~DirectFileWriter() {} |
| 48 | 48 |
| 49 virtual int Open(const char* path, int flags, mode_t mode); | 49 virtual int Open(const char* path, int flags, mode_t mode); |
| 50 virtual ssize_t Write(const void* bytes, size_t count); | 50 virtual ssize_t Write(const void* bytes, size_t count); |
| 51 virtual int Close(); | 51 virtual int Close(); |
| 52 | 52 |
| 53 int fd() const { return fd_; } | 53 int fd() const { return fd_; } |
| 54 | 54 |
| 55 private: | 55 private: |
| 56 int fd_; | 56 int fd_; |
| 57 | 57 |
| 58 DISALLOW_COPY_AND_ASSIGN(DirectFileWriter); | 58 DISALLOW_COPY_AND_ASSIGN(DirectFileWriter); |
| 59 }; | 59 }; |
| 60 | 60 |
| 61 class ScopedFileWriterCloser { | 61 class ScopedFileWriterCloser { |
| 62 public: | 62 public: |
| 63 explicit ScopedFileWriterCloser(FileWriter* writer) : writer_(writer) {} | 63 explicit ScopedFileWriterCloser(FileWriter* writer) : writer_(writer) {} |
| 64 ~ScopedFileWriterCloser() { | 64 ~ScopedFileWriterCloser() { |
| 65 int err = writer_->Close(); | 65 int err = writer_->Close(); |
| 66 if (err) | 66 if (err) |
| 67 LOG(ERROR) << "FileWriter::Close failed: " | 67 LOG(ERROR) << "FileWriter::Close failed: " |
| 68 << utils::ErrnoNumberAsString(-err); | 68 << utils::ErrnoNumberAsString(-err); |
| 69 } | 69 } |
| 70 private: | 70 private: |
| 71 FileWriter* writer_; | 71 FileWriter* writer_; |
| 72 | 72 |
| 73 DISALLOW_COPY_AND_ASSIGN(ScopedFileWriterCloser); | 73 DISALLOW_COPY_AND_ASSIGN(ScopedFileWriterCloser); |
| 74 }; | 74 }; |
| 75 | 75 |
| 76 } // namespace chromeos_update_engine | 76 } // namespace chromeos_update_engine |
| 77 | 77 |
| 78 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_FILE_WRITER_H__ | 78 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_FILE_WRITER_H__ |
| OLD | NEW |