OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium 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 #include "nacl_io/html5fs/html5_fs.h" | 5 #include "nacl_io/html5fs/html5_fs.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <stdlib.h> | 9 #include <stdlib.h> |
10 #include <string.h> | 10 #include <string.h> |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 | 48 |
49 ScopedNode node(new Html5FsNode(this, fileref)); | 49 ScopedNode node(new Html5FsNode(this, fileref)); |
50 error = node->Init(open_flags); | 50 error = node->Init(open_flags); |
51 if (error) | 51 if (error) |
52 return error; | 52 return error; |
53 | 53 |
54 *out_node = node; | 54 *out_node = node; |
55 return 0; | 55 return 0; |
56 } | 56 } |
57 | 57 |
58 Error Html5Fs::Unlink(const Path& path) { return Remove(path); } | 58 Error Html5Fs::Unlink(const Path& path) { |
| 59 return Remove(path); |
| 60 } |
59 | 61 |
60 Error Html5Fs::Mkdir(const Path& path, int permissions) { | 62 Error Html5Fs::Mkdir(const Path& path, int permissions) { |
61 Error error = BlockUntilFilesystemOpen(); | 63 Error error = BlockUntilFilesystemOpen(); |
62 if (error) | 64 if (error) |
63 return error; | 65 return error; |
64 | 66 |
65 // FileRef returns PP_ERROR_NOACCESS which is translated to EACCES if you | 67 // FileRef returns PP_ERROR_NOACCESS which is translated to EACCES if you |
66 // try to create the root directory. EEXIST is a better errno here. | 68 // try to create the root directory. EEXIST is a better errno here. |
67 if (path.Top()) | 69 if (path.Top()) |
68 return EEXIST; | 70 return EEXIST; |
69 | 71 |
70 ScopedResource fileref_resource( | 72 ScopedResource fileref_resource( |
71 ppapi(), | 73 ppapi(), |
72 ppapi()->GetFileRefInterface()->Create(filesystem_resource_, | 74 ppapi()->GetFileRefInterface()->Create(filesystem_resource_, |
73 path.Join().c_str())); | 75 path.Join().c_str())); |
74 if (!fileref_resource.pp_resource()) | 76 if (!fileref_resource.pp_resource()) |
75 return ENOENT; | 77 return ENOENT; |
76 | 78 |
77 int32_t result = ppapi()->GetFileRefInterface()->MakeDirectory( | 79 int32_t result = ppapi()->GetFileRefInterface()->MakeDirectory( |
78 fileref_resource.pp_resource(), PP_FALSE, PP_BlockUntilComplete()); | 80 fileref_resource.pp_resource(), PP_FALSE, PP_BlockUntilComplete()); |
79 if (result != PP_OK) | 81 if (result != PP_OK) |
80 return PPErrorToErrno(result); | 82 return PPErrorToErrno(result); |
81 | 83 |
82 return 0; | 84 return 0; |
83 } | 85 } |
84 | 86 |
85 Error Html5Fs::Rmdir(const Path& path) { return Remove(path); } | 87 Error Html5Fs::Rmdir(const Path& path) { |
| 88 return Remove(path); |
| 89 } |
86 | 90 |
87 Error Html5Fs::Remove(const Path& path) { | 91 Error Html5Fs::Remove(const Path& path) { |
88 Error error = BlockUntilFilesystemOpen(); | 92 Error error = BlockUntilFilesystemOpen(); |
89 if (error) | 93 if (error) |
90 return error; | 94 return error; |
91 | 95 |
92 ScopedResource fileref_resource( | 96 ScopedResource fileref_resource( |
93 ppapi(), | 97 ppapi(), |
94 ppapi()->GetFileRefInterface()->Create(filesystem_resource_, | 98 ppapi()->GetFileRefInterface()->Create(filesystem_resource_, |
95 path.Join().c_str())); | 99 path.Join().c_str())); |
(...skipping 20 matching lines...) Expand all Loading... |
116 if (!fileref_resource.pp_resource()) | 120 if (!fileref_resource.pp_resource()) |
117 return ENOENT; | 121 return ENOENT; |
118 | 122 |
119 ScopedResource new_fileref_resource( | 123 ScopedResource new_fileref_resource( |
120 ppapi(), | 124 ppapi(), |
121 ppapi()->GetFileRefInterface()->Create(filesystem_resource_, | 125 ppapi()->GetFileRefInterface()->Create(filesystem_resource_, |
122 newpath.Join().c_str())); | 126 newpath.Join().c_str())); |
123 if (!new_fileref_resource.pp_resource()) | 127 if (!new_fileref_resource.pp_resource()) |
124 return ENOENT; | 128 return ENOENT; |
125 | 129 |
126 int32_t result = ppapi()->GetFileRefInterface()->Rename( | 130 int32_t result = |
127 fileref_resource.pp_resource(), new_fileref_resource.pp_resource(), | 131 ppapi()->GetFileRefInterface()->Rename(fileref_resource.pp_resource(), |
128 PP_BlockUntilComplete()); | 132 new_fileref_resource.pp_resource(), |
| 133 PP_BlockUntilComplete()); |
129 if (result != PP_OK) | 134 if (result != PP_OK) |
130 return PPErrorToErrno(result); | 135 return PPErrorToErrno(result); |
131 | 136 |
132 return 0; | 137 return 0; |
133 } | 138 } |
134 | 139 |
135 Html5Fs::Html5Fs() | 140 Html5Fs::Html5Fs() |
136 : filesystem_resource_(0), | 141 : filesystem_resource_(0), |
137 filesystem_open_has_result_(false), | 142 filesystem_open_has_result_(false), |
138 filesystem_open_error_(0) {} | 143 filesystem_open_error_(0) { |
| 144 } |
139 | 145 |
140 Error Html5Fs::Init(const FsInitArgs& args) { | 146 Error Html5Fs::Init(const FsInitArgs& args) { |
141 Error error = Filesystem::Init(args); | 147 Error error = Filesystem::Init(args); |
142 if (error) | 148 if (error) |
143 return error; | 149 return error; |
144 | 150 |
145 if (!args.ppapi) | 151 if (!args.ppapi) |
146 return ENOSYS; | 152 return ENOSYS; |
147 | 153 |
148 pthread_cond_init(&filesystem_open_cond_, NULL); | 154 pthread_cond_init(&filesystem_open_cond_, NULL); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 } | 233 } |
228 | 234 |
229 void Html5Fs::FilesystemOpenCallback(int32_t result) { | 235 void Html5Fs::FilesystemOpenCallback(int32_t result) { |
230 AUTO_LOCK(filesysem_open_lock_); | 236 AUTO_LOCK(filesysem_open_lock_); |
231 filesystem_open_has_result_ = true; | 237 filesystem_open_has_result_ = true; |
232 filesystem_open_error_ = PPErrorToErrno(result); | 238 filesystem_open_error_ = PPErrorToErrno(result); |
233 pthread_cond_signal(&filesystem_open_cond_); | 239 pthread_cond_signal(&filesystem_open_cond_); |
234 } | 240 } |
235 | 241 |
236 } // namespace nacl_io | 242 } // namespace nacl_io |
OLD | NEW |