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.
5 #include "base/files/file.h"
6 #include "base/files/file_path.h"
9 #include "base/files/file_posix_hooks_internal.h"
17 is_symbolic_link(false) {
24 : error_details_(FILE_ERROR_FAILED
),
30 File::File(const FilePath
& name
, uint32 flags
)
31 : error_details_(FILE_OK
),
34 Initialize(name
, flags
);
38 File::File(PlatformFile platform_file
)
39 : file_(platform_file
),
40 error_details_(FILE_OK
),
44 DCHECK_GE(platform_file
, -1);
46 ProtectFileDescriptor(platform_file
);
50 File::File(Error error_details
)
51 : error_details_(error_details
),
56 File::File(RValue other
)
57 : file_(other
.object
->TakePlatformFile()),
58 error_details_(other
.object
->error_details()),
59 created_(other
.object
->created()),
60 async_(other
.object
->async_
) {
63 ProtectFileDescriptor(GetPlatformFile());
68 // Go through the AssertIOAllowed logic.
72 File
& File::operator=(RValue other
) {
73 if (this != other
.object
) {
75 SetPlatformFile(other
.object
->TakePlatformFile());
76 error_details_
= other
.object
->error_details();
77 created_
= other
.object
->created();
78 async_
= other
.object
->async_
;
84 void File::Initialize(const FilePath
& name
, uint32 flags
) {
85 if (name
.ReferencesParent()) {
86 error_details_
= FILE_ERROR_ACCESS_DENIED
;
89 InitializeUnsafe(name
, flags
);
93 std::string
File::ErrorToString(Error error
) {
97 case FILE_ERROR_FAILED
:
98 return "FILE_ERROR_FAILED";
99 case FILE_ERROR_IN_USE
:
100 return "FILE_ERROR_IN_USE";
101 case FILE_ERROR_EXISTS
:
102 return "FILE_ERROR_EXISTS";
103 case FILE_ERROR_NOT_FOUND
:
104 return "FILE_ERROR_NOT_FOUND";
105 case FILE_ERROR_ACCESS_DENIED
:
106 return "FILE_ERROR_ACCESS_DENIED";
107 case FILE_ERROR_TOO_MANY_OPENED
:
108 return "FILE_ERROR_TOO_MANY_OPENED";
109 case FILE_ERROR_NO_MEMORY
:
110 return "FILE_ERROR_NO_MEMORY";
111 case FILE_ERROR_NO_SPACE
:
112 return "FILE_ERROR_NO_SPACE";
113 case FILE_ERROR_NOT_A_DIRECTORY
:
114 return "FILE_ERROR_NOT_A_DIRECTORY";
115 case FILE_ERROR_INVALID_OPERATION
:
116 return "FILE_ERROR_INVALID_OPERATION";
117 case FILE_ERROR_SECURITY
:
118 return "FILE_ERROR_SECURITY";
119 case FILE_ERROR_ABORT
:
120 return "FILE_ERROR_ABORT";
121 case FILE_ERROR_NOT_A_FILE
:
122 return "FILE_ERROR_NOT_A_FILE";
123 case FILE_ERROR_NOT_EMPTY
:
124 return "FILE_ERROR_NOT_EMPTY";
125 case FILE_ERROR_INVALID_URL
:
126 return "FILE_ERROR_INVALID_URL";
128 return "FILE_ERROR_IO";