/src/brpc/src/butil/files/file.cc
Line | Count | Source |
1 | | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 | | // Use of this source code is governed by a BSD-style license that can be |
3 | | // found in the LICENSE file. |
4 | | |
5 | | #include "butil/files/file.h" |
6 | | #include "butil/files/file_path.h" |
7 | | |
8 | | namespace butil { |
9 | | |
10 | | File::Info::Info() |
11 | 0 | : size(0), |
12 | 0 | is_directory(false), |
13 | 0 | is_symbolic_link(false) { |
14 | 0 | } |
15 | | |
16 | 0 | File::Info::~Info() { |
17 | 0 | } |
18 | | |
19 | | File::File() |
20 | 0 | : error_details_(FILE_ERROR_FAILED), |
21 | 0 | created_(false), |
22 | 0 | async_(false) { |
23 | 0 | } |
24 | | |
25 | | #if !defined(OS_NACL) |
26 | | File::File(const FilePath& name, uint32_t flags) |
27 | 0 | : error_details_(FILE_OK), |
28 | 0 | created_(false), |
29 | 0 | async_(false) { |
30 | 0 | Initialize(name, flags); |
31 | 0 | } |
32 | | #endif |
33 | | |
34 | | File::File(PlatformFile platform_file) |
35 | 0 | : file_(platform_file), |
36 | 0 | error_details_(FILE_OK), |
37 | 0 | created_(false), |
38 | 0 | async_(false) { |
39 | 0 | #if defined(OS_POSIX) |
40 | 0 | DCHECK_GE(platform_file, -1); |
41 | 0 | #endif |
42 | 0 | } |
43 | | |
44 | | File::File(Error error_details) |
45 | 0 | : error_details_(error_details), |
46 | 0 | created_(false), |
47 | 0 | async_(false) { |
48 | 0 | } |
49 | | |
50 | | File::File(RValue other) |
51 | 0 | : file_(other.object->TakePlatformFile()), |
52 | 0 | error_details_(other.object->error_details()), |
53 | 0 | created_(other.object->created()), |
54 | 0 | async_(other.object->async_) { |
55 | 0 | } |
56 | | |
57 | 0 | File::~File() { |
58 | | // Go through the AssertIOAllowed logic. |
59 | 0 | Close(); |
60 | 0 | } |
61 | | |
62 | 0 | File& File::operator=(RValue other) { |
63 | 0 | if (this != other.object) { |
64 | 0 | Close(); |
65 | 0 | SetPlatformFile(other.object->TakePlatformFile()); |
66 | 0 | error_details_ = other.object->error_details(); |
67 | 0 | created_ = other.object->created(); |
68 | 0 | async_ = other.object->async_; |
69 | 0 | } |
70 | 0 | return *this; |
71 | 0 | } |
72 | | |
73 | | #if !defined(OS_NACL) |
74 | 0 | void File::Initialize(const FilePath& name, uint32_t flags) { |
75 | 0 | if (name.ReferencesParent()) { |
76 | 0 | error_details_ = FILE_ERROR_ACCESS_DENIED; |
77 | 0 | return; |
78 | 0 | } |
79 | 0 | InitializeUnsafe(name, flags); |
80 | 0 | } |
81 | | #endif |
82 | | |
83 | 0 | std::string File::ErrorToString(Error error) { |
84 | 0 | switch (error) { |
85 | 0 | case FILE_OK: |
86 | 0 | return "FILE_OK"; |
87 | 0 | case FILE_ERROR_FAILED: |
88 | 0 | return "FILE_ERROR_FAILED"; |
89 | 0 | case FILE_ERROR_IN_USE: |
90 | 0 | return "FILE_ERROR_IN_USE"; |
91 | 0 | case FILE_ERROR_EXISTS: |
92 | 0 | return "FILE_ERROR_EXISTS"; |
93 | 0 | case FILE_ERROR_NOT_FOUND: |
94 | 0 | return "FILE_ERROR_NOT_FOUND"; |
95 | 0 | case FILE_ERROR_ACCESS_DENIED: |
96 | 0 | return "FILE_ERROR_ACCESS_DENIED"; |
97 | 0 | case FILE_ERROR_TOO_MANY_OPENED: |
98 | 0 | return "FILE_ERROR_TOO_MANY_OPENED"; |
99 | 0 | case FILE_ERROR_NO_MEMORY: |
100 | 0 | return "FILE_ERROR_NO_MEMORY"; |
101 | 0 | case FILE_ERROR_NO_SPACE: |
102 | 0 | return "FILE_ERROR_NO_SPACE"; |
103 | 0 | case FILE_ERROR_NOT_A_DIRECTORY: |
104 | 0 | return "FILE_ERROR_NOT_A_DIRECTORY"; |
105 | 0 | case FILE_ERROR_INVALID_OPERATION: |
106 | 0 | return "FILE_ERROR_INVALID_OPERATION"; |
107 | 0 | case FILE_ERROR_SECURITY: |
108 | 0 | return "FILE_ERROR_SECURITY"; |
109 | 0 | case FILE_ERROR_ABORT: |
110 | 0 | return "FILE_ERROR_ABORT"; |
111 | 0 | case FILE_ERROR_NOT_A_FILE: |
112 | 0 | return "FILE_ERROR_NOT_A_FILE"; |
113 | 0 | case FILE_ERROR_NOT_EMPTY: |
114 | 0 | return "FILE_ERROR_NOT_EMPTY"; |
115 | 0 | case FILE_ERROR_INVALID_URL: |
116 | 0 | return "FILE_ERROR_INVALID_URL"; |
117 | 0 | case FILE_ERROR_IO: |
118 | 0 | return "FILE_ERROR_IO"; |
119 | 0 | case FILE_ERROR_MAX: |
120 | 0 | break; |
121 | 0 | } |
122 | | |
123 | 0 | NOTREACHED(); |
124 | 0 | return ""; |
125 | 0 | } |
126 | | |
127 | | } // namespace butil |