2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
23 #include <dpl/log/log.h>
25 #include <Commons/FunctionDeclaration.h>
26 #include <Commons/Exception.h>
27 #include <Commons/WrtAccess/WrtAccess.h>
30 #include "EventCopy.h"
31 #include "EventMove.h"
32 #include "EventListNodes.h"
33 #include "EventOpen.h"
34 #include "EventReadText.h"
35 #include <CommonsJavaScript/JSCallbackManager.h>
36 #include <CommonsJavaScript/Validator.h>
37 #include <CommonsJavaScript/JSUtils.h>
38 #include <CommonsJavaScript/Utils.h>
39 #include <JSTizenExceptionFactory.h>
40 #include <JSTizenException.h>
41 #include <SecurityExceptions.h>
42 #include "FilesystemUtils.h"
43 #include "Converter.h"
44 #include "plugin_config.h"
45 #include "Encodings.h"
46 #include "JSFilestream.h"
47 #include "ResponseDispatcher.h"
48 #include "FilesystemAsyncCallbackManager.h"
50 using namespace WrtDeviceApis::Commons;
51 using namespace WrtDeviceApis::CommonsJavaScript;
52 using namespace DeviceAPI::Common;
55 #define PLUGIN_NAME "File"
56 #define PROPERTY_PARENT "parent"
57 #define PROPERTY_READ_ONLY "readOnly"
58 #define PROPERTY_IS_FILE "isFile"
59 #define PROPERTY_IS_DIRECTORY "isDirectory"
60 #define PROPERTY_CREATED "created"
61 #define PROPERTY_MODIFIED "modified"
62 #define PROPERTY_PATH "path"
63 #define PROPERTY_NAME "name"
64 #define PROPERTY_FULL_PATH "fullPath"
65 #define PROPERTY_FILE_SIZE "fileSize"
66 #define PROPERTY_LENGTH "length"
69 JSValueRef getFunctionOrNull(JSContextRef ctx, JSValueRef arg)
71 if (Validator(ctx).isCallback(arg)) {
73 } else if (!JSValueIsNull(ctx, arg) && !JSValueIsUndefined(ctx, arg)) {
74 ThrowMsg(ConversionException, "Not a function nor JS null.");
81 JSValueRef getFunction(JSContextRef ctx, JSValueRef arg)
83 if (Validator(ctx).isCallback(arg)) {
86 ThrowMsg(ConversionException, "Not a function nor JS null.");
91 namespace Filesystem {
93 JSClassRef JSFile::m_classRef = 0;
95 JSClassDefinition JSFile::m_classInfo = {
97 kJSClassAttributeNone,
115 JSStaticValue JSFile::m_properties[] = {
116 { PROPERTY_PARENT, getProperty, NULL, kJSPropertyAttributeReadOnly },
117 { PROPERTY_READ_ONLY, getProperty, NULL, kJSPropertyAttributeReadOnly },
118 { PROPERTY_IS_FILE, getProperty, NULL, kJSPropertyAttributeReadOnly },
119 { PROPERTY_IS_DIRECTORY, getProperty, NULL, kJSPropertyAttributeReadOnly },
120 { PROPERTY_CREATED, getProperty, NULL, kJSPropertyAttributeReadOnly },
121 { PROPERTY_MODIFIED, getProperty, NULL, kJSPropertyAttributeReadOnly },
122 { PROPERTY_PATH, getProperty, NULL, kJSPropertyAttributeReadOnly },
123 { PROPERTY_NAME, getProperty, NULL, kJSPropertyAttributeReadOnly },
124 { PROPERTY_FULL_PATH, getProperty, NULL, kJSPropertyAttributeReadOnly },
125 { PROPERTY_FILE_SIZE, getProperty, NULL, kJSPropertyAttributeReadOnly },
126 { PROPERTY_LENGTH, getProperty, NULL, kJSPropertyAttributeReadOnly },
130 JSStaticFunction JSFile::m_functions[] = {
131 { "toURI", toUri, kJSPropertyAttributeNone },
132 { "listFiles", listFiles, kJSPropertyAttributeNone },
133 { "openStream", openStream, kJSPropertyAttributeNone },
134 { "readAsText", readAsText, kJSPropertyAttributeNone },
135 { "copyTo", copyTo, kJSPropertyAttributeNone },
136 { "moveTo", moveTo, kJSPropertyAttributeNone },
137 { "createDirectory", createDirectory, kJSPropertyAttributeNone },
138 { "createFile", createFile, kJSPropertyAttributeNone },
139 { "resolve", resolve, kJSPropertyAttributeNone },
140 { "deleteDirectory", deleteDirectory, kJSPropertyAttributeNone },
141 { "deleteFile", deleteFile, kJSPropertyAttributeNone },
145 void JSFile::initialize(JSContextRef context,
150 void JSFile::finalize(JSObjectRef object)
152 PrivateObject* privateObject = static_cast<PrivateObject*>(JSObjectGetPrivate(object));
154 JSObjectSetPrivate(object, NULL);
155 delete privateObject;
159 const JSClassRef JSFile::getClassRef()
162 m_classRef = JSClassCreate(&m_classInfo);
167 const JSClassDefinition* JSFile::getClassInfo()
172 JSValueRef JSFile::getProperty(JSContextRef context,
174 JSStringRef propertyName,
175 JSValueRef* exception)
177 PrivateObject* privateObject =
178 static_cast<PrivateObject*>(JSObjectGetPrivate(object));
179 if (!privateObject) {
180 LogError("Private object is not set.");
181 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch error");
184 JSContextRef globalContext = privateObject->getContext();
185 Converter converter(globalContext);
188 if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_PARENT))
190 INodePtr parent(privateObject->getObject()->getNode()->getParent());
191 PrivateObjectDef::PermissionList perms =
192 privateObject->getObject()->getParentPermissions();
193 if (parent && !perms.empty())
195 parent->setPermissions(perms.back());
197 PrivateObjectDefPtr privData(new PrivateObjectDef(parent, perms));
199 return JSUtils::makeObject(privateObject->getContext(), getClassRef(), privData);
201 return JSValueMakeNull(context);
203 else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_READ_ONLY))
205 bool readOnly = ((privateObject->getObject()->getNode()->getMode() & PM_USER_WRITE) == 0);
206 return converter.toJSValueRef(readOnly);
208 else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_IS_FILE))
210 bool isFile = (privateObject->getObject()->getNode()->getType() == NT_FILE);
211 return converter.toJSValueRef(isFile);
213 else if (JSStringIsEqualToUTF8CString(propertyName,
214 PROPERTY_IS_DIRECTORY))
216 bool isDirectory = (privateObject->getObject()->getNode()->getType() == NT_DIRECTORY);
217 return converter.toJSValueRef(isDirectory);
219 else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_CREATED))
221 std::time_t created = privateObject->getObject()->getNode()->getCreated();
222 return converter.toJSValueRef(created);
224 else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_MODIFIED))
226 std::time_t modified = privateObject->getObject()->getNode()->getModified();
227 return converter.toJSValueRef(modified);
229 else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_PATH))
231 std::string fpath = privateObject->getObject()->getNode()->getPath()->getFullPath();
232 std::string vpath = Utils::toVirtualPath(globalContext, fpath);
233 std::string::size_type pos = vpath.rfind(IPath::getSeparator());
234 std::string path = (std::string::npos != pos ? vpath.substr(0, pos + 1) : vpath);
235 return converter.toJSValueRef(path);
237 else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_NAME))
239 std::string fpath = privateObject->getObject()->getNode()->getPath()->getFullPath();
240 std::string vpath = Utils::toVirtualPath(globalContext, fpath);
242 std::string::size_type pos = vpath.rfind(IPath::getSeparator());
244 if (std::string::npos != pos) {
245 name = vpath.substr(pos + 1);
247 return converter.toJSValueRef(name);
249 else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_FULL_PATH))
251 std::string path = privateObject->getObject()->getNode()->getPath()->getFullPath();
252 return converter.toJSValueRef(Utils::toVirtualPath(globalContext, path));
254 else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_FILE_SIZE))
256 if (privateObject->getObject()->getNode()->getType() == NT_DIRECTORY)
258 return JSValueMakeUndefined(context);
260 return converter.toJSValueRef(privateObject->getObject()->getNode()->getSize());
262 else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_LENGTH))
264 if (privateObject->getObject()->getNode()->getType() == NT_FILE) {
265 return JSValueMakeUndefined(context);
267 // TODO: think about more efficent solution!
268 NodeList children = privateObject->getObject()->getNode()->getChildNodes();
269 return converter.toJSValueRef(children.size());
272 catch (const WrtDeviceApis::Commons::Exception& ex) {
273 LogError("Exception: " << ex.GetMessage());
276 else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_READ_ONLY)) {
277 bool readOnly = ((privateObject->getObject()->getNode() & PERM_WRITE) == 0);
278 return converter.toJSValueRef(readOnly);
279 } else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_IS_FILE)) {
280 bool isFile = (privateObject->getObject()->getNode()->getType() == NT_FILE);
281 return converter.toJSValueRef(isFile);
282 } else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_IS_DIRECTORY)) {
283 bool isDirectory =(privateObject->getObject()->getNode()->getType() == NT_DIRECTORY);
284 return converter.toJSValueRef(isDirectory);
285 } else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_CREATED)) {
286 std::time_t created = privateObject->getObject()->getNode()->getCreated();
287 return converter.toJSValueRef(created);
288 } else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_MODIFIED)) {
289 std::time_t modified = privateObject->getObject()->getNode()->getModified();
290 return converter.toJSValueRef(modified);
291 } else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_PATH)) {
292 std::string fpath = privateObject->getObject()->getNode()->getPath()->getFullPath();
293 std::string vpath = Utils::toVirtualPath(globalContext, fpath);
294 std::string::size_type pos = vpath.rfind(IPath::getSeparator());
295 std::string path = (std::string::npos != pos ? vpath.substr(0, pos + 1) : vpath);
296 return converter.toJSValueRef(path);
297 } else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_NAME)) {
298 std::string fpath = privateObject->getObject()->getNode()->getPath()->getFullPath();
299 std::string vpath = Utils::toVirtualPath(globalContext, fpath);
301 std::string::size_type pos = vpath.rfind(IPath::getSeparator());
302 if (std::string::npos != pos) {
303 name = vpath.substr(pos + 1);
305 return converter.toJSValueRef(name);
306 } else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_FULL_PATH)) {
307 std::string path = privateObject->getObject()->getNode()->getPath()->getFullPath();
308 return converter.toJSValueRef(Utils::toVirtualPath(globalContext, path));
309 } else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_FILE_SIZE)) {
310 if (privateObject->getObject()->getNode()->getType() == NT_DIRECTORY) {
311 return JSValueMakeUndefined(context);
313 return converter.toJSValueRef(privateObject->getObject()->getNode()->getSize());
314 } else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_LENGTH)) {
315 if (privateObject->getObject()->getNode()->getType() == NT_FILE) {
316 return JSValueMakeUndefined(context);
318 NodeList children = privateObject->getObject()->getNode()->getChildNodes();
319 return converter.toJSValueRef(children.size());
321 } catch (const WrtDeviceApis::Commons::Exception& ex) {
322 LogWarning("trying to get incorrect value");
325 return JSValueMakeUndefined(context);
328 void JSFile::getPropertyNames(JSContextRef context,
330 JSPropertyNameAccumulatorRef propertyNames)
334 bool JSFile::hasInstance(JSContextRef context,
335 JSObjectRef constructor,
336 JSValueRef possibleInstance,
337 JSValueRef* exception)
339 return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
342 JSValueRef JSFile::toUri(JSContextRef context,
344 JSObjectRef thisObject,
346 const JSValueRef argv[],
347 JSValueRef* exception)
349 PrivateObject* privateObject = static_cast<PrivateObject*>(JSObjectGetPrivate(thisObject));
350 if (!privateObject) {
351 LogError("Private object is not set.");
352 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch error");
355 Converter converter(context);
357 AceSecurityStatus status = FILESYSTEM_CHECK_ACCESS(FILESYSTEM_FUNCTION_API_TO_URI);
358 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
360 int widgetId = WrtAccessSingleton::Instance().getWidgetId();
361 return converter.toJSValueRef(privateObject->getObject()->getNode()->toUri(widgetId));
362 } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
363 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, ex.GetMessage());
364 } catch (const WrtDeviceApis::Commons::UnsupportedException& ex) {
365 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, ex.GetMessage());
366 } catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
367 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, ex.GetMessage());
368 } catch(const WrtDeviceApis::Commons::Exception& ex) {
369 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, ex.GetMessage());
373 JSValueRef JSFile::listFiles(JSContextRef context,
375 JSObjectRef thisObject,
377 const JSValueRef argv[],
378 JSValueRef* exception)
380 PrivateObject* privateObject = static_cast<PrivateObject*>(JSObjectGetPrivate(thisObject));
381 if (!privateObject) {
382 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch error");
387 JSContextRef globalContext = privateObject->getContext();
389 JSValueRef reserveArguments[3];
390 JSCallbackManagerPtr cbm = JSCallbackManager::createObject(globalContext);
394 AceSecurityStatus status = FILESYSTEM_CHECK_ACCESS(FILESYSTEM_FUNCTION_API_LIST_FILES);
395 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
397 for (index = 0; index < 3; index++)
400 reserveArguments[index] = argv[index];
402 reserveArguments[index] = JSValueMakeUndefined(context);
405 JSValueRef onSuccess = getFunction(globalContext, reserveArguments[0]);
406 JSValueRef onError = NULL;
410 onError = getFunctionOrNull(globalContext, reserveArguments[1]);
413 cbm->setOnSuccess(onSuccess);
414 cbm->setOnError(onError);
415 cbm->setObject(thisObject);
417 Converter converter(globalContext);
419 EventListNodesPtr event(new EventListNodes(privateObject->getObject()->getNode()));
421 if (JSValueIsNull(context, reserveArguments[2]) == false &&
422 JSValueIsUndefined(context, reserveArguments[2]) == false) {
423 event->setFilter(converter.toNodeFilter(reserveArguments[2]));
426 PrivateObjectDef::PermissionList perms =
427 privateObject->getObject()->getParentPermissions();
428 perms.push_back(privateObject->getObject()->getNode()->getPermissions());
430 ListFilesPrivateDataPtr privData(new ListFilesPrivateData(cbm, perms));
432 event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData>(privData));
433 event->setForAsynchronousCall(&ResponseDispatcher::getInstance());
435 privateObject->getObject()->getNode()->getChildNodes(event);
436 FilesystemAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
439 } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
440 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, ex.GetMessage());
441 } catch (const WrtDeviceApis::Commons::UnsupportedException& ex) {
442 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, ex.GetMessage());
443 } catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
444 cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, ex.GetMessage()));
445 } catch(const WrtDeviceApis::Commons::Exception& ex) {
446 cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, ex.GetMessage()));
449 return JSValueMakeUndefined(context);
452 JSValueRef JSFile::openStream(JSContextRef context,
454 JSObjectRef thisObject,
455 size_t argumentCount,
456 const JSValueRef arguments[],
457 JSValueRef* exception)
459 PrivateObject* privateObject = static_cast<PrivateObject*>(JSObjectGetPrivate(thisObject));
460 if (!privateObject) {
461 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch error");
464 JSContextRef globalContext = privateObject->getContext();
465 JSCallbackManagerPtr cbm = JSCallbackManager::createObject(globalContext);
468 JSValueRef reserveArguments[4];
472 for (index = 0; index < 4; index++) {
473 if (index < argumentCount)
474 reserveArguments[index] = arguments[index];
476 reserveArguments[index] = JSValueMakeUndefined(context);
480 JSValueRef onSuccess = getFunction(globalContext, reserveArguments[1]);
481 JSValueRef onError = NULL;
483 onError = getFunctionOrNull(globalContext, reserveArguments[2]);
485 cbm->setOnSuccess(onSuccess);
486 cbm->setOnError(onError);
487 cbm->setObject(thisObject);
490 Converter converter(globalContext);
492 AccessMode mode = converter.toAccessMode(reserveArguments[0]);
493 std::string encoding = Encodings::UTF8;
494 if (argumentCount > 3) {
495 if(!JSValueIsNull(globalContext, reserveArguments[3]) && !JSValueIsUndefined(globalContext, reserveArguments[3])){
496 encoding = converter.toEncoding(reserveArguments[3]);
500 if ((AM_READ != mode) && (PERM_READ == privateObject->getObject()->getNode()->getPermissions())) {
501 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::PERMISSION_DENIED_ERROR, "Permission denied error");
504 std::string path = privateObject->getObject()->getNode()->getPath()->getFullPath();
505 std::string vpath = Utils::toVirtualPath(globalContext, path);
507 AccessModeInfo am = AccessModeInfo(mode, vpath);
508 AceSecurityStatus status = FILESYSTEM_ACCESSMODE_CHECK_ACCESS(FILESYSTEM_FUNCTION_API_OPEN_STREAM, am);
510 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
512 EventOpenPtr event(new EventOpen(mode));
513 event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData>(cbm));
514 event->setCharSet(encoding);
515 event->setForAsynchronousCall(&ResponseDispatcher::getInstance());
516 FilesystemAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
518 privateObject->getObject()->getNode()->open(event);
521 } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
522 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, ex.GetMessage());
523 } catch (const WrtDeviceApis::Commons::UnsupportedException& ex) {
524 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, ex.GetMessage());
525 } catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
526 cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, ex.GetMessage()));
527 } catch(const WrtDeviceApis::Commons::Exception& ex) {
528 cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, ex.GetMessage()));
531 return JSValueMakeUndefined(context);
534 JSValueRef JSFile::readAsText(JSContextRef context,
536 JSObjectRef thisObject,
538 const JSValueRef argv[],
539 JSValueRef* exception)
541 PrivateObject* privateObject = static_cast<PrivateObject*>(JSObjectGetPrivate(thisObject));
542 if (!privateObject) {
543 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch error");
547 JSContextRef globalContext = privateObject->getContext();
548 AceSecurityStatus status = FILESYSTEM_CHECK_ACCESS(FILESYSTEM_FUNCTION_API_READ_AS_TEXT);
551 JSValueRef reserveArguments[3];
552 JSCallbackManagerPtr cbm = JSCallbackManager::createObject(globalContext);
556 for (index = 0; index < 3; index++) {
558 reserveArguments[index] = argv[index];
560 reserveArguments[index] = JSValueMakeUndefined(context);
563 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
565 JSValueRef onSuccess = getFunction(globalContext, reserveArguments[0]);
566 JSValueRef onError = NULL;
569 onError = getFunctionOrNull(globalContext, reserveArguments[1]);
572 cbm->setOnSuccess(onSuccess);
573 cbm->setOnError(onError);
574 cbm->setObject(thisObject);
576 Converter converter(context);
577 std::string src = Encodings::UTF8;
579 if (!JSValueIsNull(context, reserveArguments[2]) && !JSValueIsUndefined(context, reserveArguments[2])) {
580 src = converter.toEncoding(reserveArguments[2]);
584 if (NT_FILE != privateObject->getObject()->getNode()->getType()) {
585 cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::IO_ERROR, "IO error"));
586 return JSValueMakeUndefined(context);
589 EventReadTextPtr event(new EventReadText());
590 event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData,JSCallbackManager>(cbm));
591 event->setCharSet(src);
592 event->setForAsynchronousCall(&ResponseDispatcher::getInstance());
593 FilesystemAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
595 privateObject->getObject()->getNode()->read(event);
597 } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
598 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, ex.GetMessage());
599 } catch (const WrtDeviceApis::Commons::UnsupportedException& ex) {
600 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, ex.GetMessage());
601 } catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
602 cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, ex.GetMessage()));
603 } catch(const WrtDeviceApis::Commons::Exception& ex) {
604 cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, ex.GetMessage()));
607 return JSValueMakeUndefined(context);
610 JSValueRef JSFile::copyTo(JSContextRef context,
612 JSObjectRef thisObject,
614 const JSValueRef argv[],
615 JSValueRef* exception)
617 PrivateObject* privateObject = static_cast<PrivateObject*>(JSObjectGetPrivate(thisObject));
618 if (!privateObject) {
619 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch error");
622 JSContextRef globalContext = privateObject->getContext();
624 JSValueRef reserveArguments[5];
625 JSCallbackManagerPtr cbm = JSCallbackManager::createObject(globalContext);
629 for (index = 0; index < 5; index++)
632 reserveArguments[index] = argv[index];
634 reserveArguments[index] = JSValueMakeUndefined(context);
637 Converter converter(globalContext);
638 JSValueRef onSuccess = NULL;
639 JSValueRef onError = NULL;
641 onSuccess = getFunctionOrNull(globalContext, reserveArguments[3]);
642 onError = getFunctionOrNull(globalContext, reserveArguments[4]);
644 cbm->setOnSuccess(onSuccess);
645 cbm->setOnError(onError);
646 cbm->setObject(thisObject);
649 //TODO add check validation for src, dest string.
650 IPathPtr src = Utils::fromVirtualPath(globalContext, converter.toString(reserveArguments[0]));
651 IPathPtr dest = Utils::fromVirtualPath(globalContext, converter.toString(reserveArguments[1]));
652 bool overwrite = converter.toBool(reserveArguments[2]);;
654 if (NT_DIRECTORY != privateObject->getObject()->getNode()->getType()) {
655 cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::IO_ERROR, "IO error"));
656 return JSValueMakeUndefined(context);
659 std::string virtualDestPath = Utils::toVirtualPath(globalContext, dest->getFullPath());
660 AccessModeInfo amode = AccessModeInfo(AM_WRITE, virtualDestPath);
661 AceSecurityStatus status = FILESYSTEM_ACCESSMODE_CHECK_ACCESS(
662 FILESYSTEM_FUNCTION_API_COPY_TO,
665 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
667 EventCopyPtr event(new EventCopy(src, dest));
670 event->setOptions(OPT_OVERWRITE);
673 event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::
677 event->setForAsynchronousCall(&ResponseDispatcher::getInstance());
678 FilesystemAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
680 IManager::getInstance().copy(event);
681 } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
682 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, ex.GetMessage());
683 } catch (const WrtDeviceApis::Commons::UnsupportedException& ex) {
684 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, ex.GetMessage());
685 } catch(const WrtDeviceApis::Commons::NotFoundException &ex) {
686 cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::NOT_FOUND_ERROR, ex.GetMessage()));
687 } catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
688 cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, ex.GetMessage()));
689 } catch(const WrtDeviceApis::Commons::Exception& ex) {
690 cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, ex.GetMessage()));
693 return JSValueMakeUndefined(context);
696 JSValueRef JSFile::moveTo(JSContextRef context,
698 JSObjectRef thisObject,
700 const JSValueRef argv[],
701 JSValueRef* exception)
703 PrivateObject* privateObject = static_cast<PrivateObject*>(JSObjectGetPrivate(thisObject));
704 if (!privateObject) {
705 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch error");
708 JSContextRef globalContext = privateObject->getContext();
713 JSValueRef reserveArguments[5];
714 JSCallbackManagerPtr cbm = JSCallbackManager::createObject(globalContext);
718 for (index = 0; index < 5; index++) {
720 reserveArguments[index] = argv[index];
722 reserveArguments[index] = JSValueMakeUndefined(context);
725 if ((privateObject->getObject()->getNode()->getPermissions() & PERM_WRITE) == 0) {
726 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::PERMISSION_DENIED_ERROR, "Permission denied error");
729 Converter converter(context);
730 JSValueRef onSuccess = NULL;
731 JSValueRef onError = NULL;
733 onSuccess = getFunctionOrNull(globalContext, reserveArguments[3]);
734 onError = getFunctionOrNull(globalContext, reserveArguments[4]);
735 cbm->setOnSuccess(onSuccess);
736 cbm->setOnError(onError);
737 cbm->setObject(thisObject);
739 if (NT_DIRECTORY != privateObject->getObject()->getNode()->getType()) {
740 cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::IO_ERROR, "io error"));
741 return JSValueMakeUndefined(context);
744 IPathPtr src = Utils::fromVirtualPath(globalContext, converter.toString(reserveArguments[0]));
745 IPathPtr dest = Utils::fromVirtualPath(globalContext, converter.toString(reserveArguments[1]));
746 bool overwrite = converter.toBool(reserveArguments[2]);
748 std::string virtualDestPath = Utils::toVirtualPath(globalContext, dest->getFullPath());
750 AccessModeInfo amode = AccessModeInfo(AM_WRITE, virtualDestPath);
751 AceSecurityStatus status = FILESYSTEM_ACCESSMODE_CHECK_ACCESS(FILESYSTEM_FUNCTION_API_MOVE_TO, amode);
753 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
755 EventMovePtr event(new EventMove(src, dest));
757 event->setOptions(OPT_OVERWRITE);
760 event->setForAsynchronousCall(&ResponseDispatcher::getInstance());
761 event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData > (cbm));
762 FilesystemAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
764 IManager::getInstance().move(event);
766 } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
767 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, ex.GetMessage());
768 } catch (const WrtDeviceApis::Commons::UnsupportedException& ex) {
769 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, ex.GetMessage());
770 } catch(const WrtDeviceApis::Commons::NotFoundException &ex) {
771 cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::NOT_FOUND_ERROR, ex.GetMessage()));
773 catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
774 cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, ex.GetMessage()));
775 } catch(const WrtDeviceApis::Commons::Exception& ex) {
776 cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, ex.GetMessage()));
778 return JSValueMakeUndefined(context);
781 JSValueRef JSFile::createDirectory(JSContextRef context,
783 JSObjectRef thisObject,
785 const JSValueRef argv[],
786 JSValueRef* exception)
788 PrivateObject* privateObject = static_cast<PrivateObject*>(JSObjectGetPrivate(thisObject));
789 if (!privateObject) {
790 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch error");
793 AceSecurityStatus status = FILESYSTEM_CHECK_ACCESS(FILESYSTEM_FUNCTION_API_CREATE_DIR);
795 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
798 Converter converter(context);
802 ThrowMsg(InvalidArgumentException, "Invalid path name");
805 IPathPtr path = converter.toPath(argv[0]);
806 INodePtr node(privateObject->getObject()->getNode()->createChild(path, NT_DIRECTORY, OPT_RECURSIVE));
807 node->setPermissions(privateObject->getObject()->getNode()->getPermissions());
809 PrivateObjectDefPtr privData(new PrivateObjectDef(node, privateObject->getObject()->getParentPermissions()));
810 privData->pushParentPermissions(privateObject->getObject()->getNode()->getPermissions());
812 return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(privateObject->getContext(), getClassRef(), privData);
813 } catch (const WrtDeviceApis::Commons::PlatformException& ex) {
814 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::IO_ERROR, ex.GetMessage());
815 } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
816 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, ex.GetMessage());
817 } catch (const WrtDeviceApis::Commons::UnsupportedException& ex) {
818 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, ex.GetMessage());
819 } catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
820 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, ex.GetMessage());
821 } catch(const WrtDeviceApis::Commons::Exception& ex) {
822 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, ex.GetMessage());
826 JSValueRef JSFile::createFile(JSContextRef context,
828 JSObjectRef thisObject,
830 const JSValueRef argv[],
831 JSValueRef* exception)
833 PrivateObject* privateObject = static_cast<PrivateObject*>(JSObjectGetPrivate(thisObject));
834 if (!privateObject) {
835 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch error");
838 AceSecurityStatus status = FILESYSTEM_CHECK_ACCESS(FILESYSTEM_FUNCTION_API_CREATE_FILE);
840 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
843 Converter converter(context);
847 ThrowMsg(InvalidArgumentException, "Invalid path name");
850 IPathPtr path = converter.toPath(argv[0]);
851 INodePtr node = privateObject->getObject()->getNode()->createChild(path, NT_FILE);
853 PrivateObjectDefPtr privData(new PrivateObjectDef(node, privateObject->getObject()->getParentPermissions()));
854 privData->pushParentPermissions(privateObject->getObject()->getNode()->getPermissions());
856 return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(privateObject->getContext(), getClassRef(), privData);
858 IPathPtr path = converter.toPath(argv[0]);
859 INodePtr node = privateObject->getObject()->getNode()->createChild(path, NT_FILE);
860 return JSUtils::makeObject(privateObject->getContext(), getClassRef(), node);*/
861 } catch (const WrtDeviceApis::Commons::PlatformException& ex) {
862 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::IO_ERROR, ex.GetMessage());
863 } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
864 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, ex.GetMessage());
865 } catch (const WrtDeviceApis::Commons::UnsupportedException& ex) {
866 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, ex.GetMessage());
867 } catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
868 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, ex.GetMessage());
869 } catch(const WrtDeviceApis::Commons::Exception& ex) {
870 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, ex.GetMessage());
875 JSValueRef JSFile::resolve(JSContextRef context,
877 JSObjectRef thisObject,
879 const JSValueRef argv[],
880 JSValueRef* exception)
882 PrivateObject* privateObject = static_cast<PrivateObject*>(JSObjectGetPrivate(thisObject));
883 if (!privateObject) {
884 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch error");
888 if (privateObject->getObject()->getNode()->getType() != NT_DIRECTORY) {
889 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::IO_ERROR, "IO error");
892 Converter converter(context);
896 ThrowMsg(InvalidArgumentException, "Invalid path name");
899 AceSecurityStatus status = FILESYSTEM_CHECK_ACCESS(FILESYSTEM_FUNCTION_API_RESOLVE);
900 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
903 IPathPtr path = converter.toPath(argv[0]);
904 INodePtr node = privateObject->getObject()->getNode()->getChild(path);
905 node->setPermissions(privateObject->getObject()->getNode()->getPermissions());
906 PrivateObjectDefPtr privData(new PrivateObjectDef(node, privateObject->getObject()->getParentPermissions()));
907 privData->pushParentPermissions(privateObject->getObject()->getNode()->getPermissions());
908 return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(privateObject->getContext(), getClassRef(), privData);
910 IPathPtr path = converter.toPath(argv[0]);
911 INodePtr node = privateObject->getObject()->getNode()->getChild(path);
912 node->setPermissions(privateObject->getObject()->getNode()->getPermissions());
913 return JSUtils::makeObject(privateObject->getContext(), getClassRef(), node);
915 } catch (const WrtDeviceApis::Commons::PlatformException& ex) {
916 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::IO_ERROR, ex.GetMessage());
917 } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
918 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, ex.GetMessage());
919 } catch (const WrtDeviceApis::Commons::UnsupportedException& ex) {
920 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, ex.GetMessage());
921 } catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
922 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, ex.GetMessage());
923 } catch(const WrtDeviceApis::Commons::NotFoundException& ex) {
924 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, ex.GetMessage());
925 } catch(const WrtDeviceApis::Commons::Exception& ex) {
926 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, ex.GetMessage());
930 JSValueRef JSFile::deleteDirectory(JSContextRef context,
932 JSObjectRef thisObject,
934 const JSValueRef argv[],
935 JSValueRef* exception)
937 PrivateObject* privateObject = static_cast<PrivateObject*>(JSObjectGetPrivate(thisObject));
938 if (!privateObject) {
939 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch error");
943 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type missmatch error");
946 JSContextRef globalContext = privateObject->getContext();
951 JSValueRef reserveArguments[4];
952 JSCallbackManagerPtr cbm = JSCallbackManager::createObject(globalContext);
955 for (index = 0; index < 4; index++) {
957 reserveArguments[index] = argv[index];
959 reserveArguments[index] = JSValueMakeUndefined(context);
962 AceSecurityStatus status = FILESYSTEM_CHECK_ACCESS(FILESYSTEM_FUNCTION_API_DELETE_DIR);
964 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
966 JSValueRef onSuccess = NULL;
967 JSValueRef onError = NULL;
969 onSuccess = getFunctionOrNull(globalContext, reserveArguments[2]);
970 onError = getFunctionOrNull(globalContext, reserveArguments[3]);
972 cbm->setOnSuccess(onSuccess);
973 cbm->setOnError(onError);
974 cbm->setObject(thisObject);
976 if ((privateObject->getObject()->getNode()->getPermissions() & PERM_WRITE) == 0) {
977 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::PERMISSION_DENIED_ERROR, "Permission denied error");
980 if (privateObject->getObject()->getNode()->getType() != NT_DIRECTORY) {
981 cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::IO_ERROR, "IO error"));
982 return JSValueMakeUndefined(context);
985 Converter converter(context);
986 IPathPtr path = Utils::fromVirtualPath(globalContext, converter.toString(reserveArguments[0]));
987 bool recursive = converter.toBool(reserveArguments[1]);
989 if (*privateObject->getObject()->getNode()->getPath() != path->getPath()) {
990 cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::IO_ERROR, "IO error"));
991 return JSValueMakeUndefined(context);
995 EventResolvePtr eventResolve(new EventResolve(path));
996 if (eventResolve->setForSynchronousCall()) {
997 IManager::getInstance().getNode(eventResolve);
998 if (!eventResolve->getResult() || (eventResolve->getExceptionCode() != WrtDeviceApis::Commons::ExceptionCodes::None)) {
999 cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::IO_ERROR, "IO error"));
1000 return JSValueMakeUndefined(context);
1003 if (eventResolve->getResult()->getType() != NT_DIRECTORY) {
1004 ThrowMsg(InvalidArgumentException, "Invalid directory");
1007 EventRemovePtr eventRemove(new EventRemove(path));
1010 eventRemove->setOptions(OPT_RECURSIVE);
1013 eventRemove->setForAsynchronousCall(&ResponseDispatcher::getInstance());
1014 eventRemove->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData > (cbm));
1015 FilesystemAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
1017 IManager::getInstance().remove(eventRemove);
1019 } catch (const WrtDeviceApis::Commons::PlatformException& ex) {
1020 cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::IO_ERROR, ex.GetMessage()));
1022 } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
1023 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, ex.GetMessage());
1024 } catch (const WrtDeviceApis::Commons::UnsupportedException& ex) {
1025 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, ex.GetMessage());
1026 } catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
1027 cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, ex.GetMessage()));
1028 } catch(const WrtDeviceApis::Commons::NotFoundException& ex) {
1029 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, ex.GetMessage());
1030 } catch(const WrtDeviceApis::Commons::Exception& ex) {
1031 cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, ex.GetMessage()));
1034 return JSValueMakeUndefined(context);
1037 JSValueRef JSFile::deleteFile(JSContextRef context,
1039 JSObjectRef thisObject,
1041 const JSValueRef argv[],
1042 JSValueRef* exception)
1046 PrivateObject* privateObject = static_cast<PrivateObject*>(JSObjectGetPrivate(thisObject));
1048 if (!privateObject) {
1049 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch error");
1052 JSContextRef globalContext = privateObject->getContext();
1055 JSValueRef reserveArguments[3];
1056 JSCallbackManagerPtr cbm = JSCallbackManager::createObject(globalContext);
1059 for (index = 0; index < 3; index++) {
1061 reserveArguments[index] = argv[index];
1063 reserveArguments[index] = JSValueMakeUndefined(context);
1066 AceSecurityStatus status = FILESYSTEM_CHECK_ACCESS(FILESYSTEM_FUNCTION_API_DELETE_FILE);
1068 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
1070 if ((privateObject->getObject()->getNode()->getPermissions() & PERM_WRITE) == 0) {
1071 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::PERMISSION_DENIED_ERROR, "Permission denied error");
1074 JSValueRef onSuccess = NULL;
1075 JSValueRef onError = NULL;
1077 onSuccess = getFunctionOrNull(globalContext, reserveArguments[1]);
1078 onError = getFunctionOrNull(globalContext, reserveArguments[2]);
1080 cbm->setOnSuccess(onSuccess);
1081 cbm->setOnError(onError);
1082 cbm->setObject(thisObject);
1084 if (privateObject->getObject()->getNode()->getType() != NT_DIRECTORY) {
1085 cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::IO_ERROR, "IO error"));
1086 return JSValueMakeUndefined(context);
1090 Converter converter(context);
1091 IPathPtr path = Utils::fromVirtualPath(globalContext, converter.toString(reserveArguments[0]));
1093 EventResolvePtr eventResolve(new EventResolve(path));
1094 if (eventResolve->setForSynchronousCall()) {
1095 IManager::getInstance().getNode(eventResolve);
1097 if (!eventResolve->getResult() ||(eventResolve->getExceptionCode() != WrtDeviceApis::Commons::ExceptionCodes::None)) {
1098 if(eventResolve->getExceptionCode() == WrtDeviceApis::Commons::ExceptionCodes::NotFoundException){
1099 LogDebug("POST IO NOT_FOUND_ERROR");
1100 ThrowMsg(NotFoundException, "Not found error");
1103 LogDebug("POST IO ERROR");
1104 cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::IO_ERROR, "IO error"));
1105 return JSValueMakeUndefined(context);
1108 if (eventResolve->getResult()->getType() != NT_FILE) {
1109 ThrowMsg(InvalidArgumentException, "Invalid directory");
1112 LogDebug("try to call async event");
1113 EventRemovePtr eventRemove(new EventRemove(path));
1114 eventRemove->setForAsynchronousCall(&ResponseDispatcher::getInstance());
1115 eventRemove->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData > (cbm));
1116 FilesystemAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
1118 IManager::getInstance().remove(eventRemove);
1121 } catch (const WrtDeviceApis::Commons::PlatformException& ex) {
1122 LogDebug("Platform Exception !!!!!!!! post io error");
1123 cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::IO_ERROR, ex.GetMessage()));
1124 } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
1125 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, ex.GetMessage());
1126 } catch (const WrtDeviceApis::Commons::UnsupportedException& ex) {
1127 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, ex.GetMessage());
1128 } catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
1129 cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, ex.GetMessage()));
1130 } catch(const WrtDeviceApis::Commons::NotFoundException& ex) {
1131 cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::NOT_FOUND_ERROR, ex.GetMessage()));
1132 } catch(const WrtDeviceApis::Commons::Exception& ex) {
1133 cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, ex.GetMessage()));
1137 return JSValueMakeUndefined(context);