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);
362 int widgetId = WrtAccessSingleton::Instance().getWidgetId();
363 return converter.toJSValueRef(privateObject->getObject()->getNode()->toUri(widgetId));
364 } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
365 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, ex.GetMessage());
366 } catch (const WrtDeviceApis::Commons::UnsupportedException& ex) {
367 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, ex.GetMessage());
368 } catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
369 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, ex.GetMessage());
370 } catch(const WrtDeviceApis::Commons::Exception& ex) {
371 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, ex.GetMessage());
375 JSValueRef JSFile::listFiles(JSContextRef context,
377 JSObjectRef thisObject,
379 const JSValueRef argv[],
380 JSValueRef* exception)
382 PrivateObject* privateObject = static_cast<PrivateObject*>(JSObjectGetPrivate(thisObject));
383 if (!privateObject) {
384 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch error");
389 JSContextRef globalContext = privateObject->getContext();
391 JSValueRef reserveArguments[3];
392 JSCallbackManagerPtr cbm = JSCallbackManager::createObject(globalContext);
396 AceSecurityStatus status = FILESYSTEM_CHECK_ACCESS(FILESYSTEM_FUNCTION_API_LIST_FILES);
397 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
399 for (index = 0; index < 3; index++)
402 reserveArguments[index] = argv[index];
404 reserveArguments[index] = JSValueMakeUndefined(context);
407 JSValueRef onSuccess = getFunction(globalContext, reserveArguments[0]);
408 JSValueRef onError = NULL;
412 onError = getFunctionOrNull(globalContext, reserveArguments[1]);
415 cbm->setOnSuccess(onSuccess);
416 cbm->setOnError(onError);
417 cbm->setObject(thisObject);
419 Converter converter(globalContext);
421 EventListNodesPtr event(new EventListNodes(privateObject->getObject()->getNode()));
423 if (JSValueIsNull(context, reserveArguments[2]) == false &&
424 JSValueIsUndefined(context, reserveArguments[2]) == false) {
425 event->setFilter(converter.toNodeFilter(reserveArguments[2]));
428 PrivateObjectDef::PermissionList perms =
429 privateObject->getObject()->getParentPermissions();
430 perms.push_back(privateObject->getObject()->getNode()->getPermissions());
432 ListFilesPrivateDataPtr privData(new ListFilesPrivateData(cbm, perms));
434 event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData>(privData));
435 event->setForAsynchronousCall(&ResponseDispatcher::getInstance());
437 privateObject->getObject()->getNode()->getChildNodes(event);
438 FilesystemAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
441 } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
442 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, ex.GetMessage());
443 } catch (const WrtDeviceApis::Commons::UnsupportedException& ex) {
444 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, ex.GetMessage());
445 } catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
446 cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, ex.GetMessage()));
447 } catch(const WrtDeviceApis::Commons::Exception& ex) {
448 cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, ex.GetMessage()));
451 return JSValueMakeUndefined(context);
454 JSValueRef JSFile::openStream(JSContextRef context,
456 JSObjectRef thisObject,
457 size_t argumentCount,
458 const JSValueRef arguments[],
459 JSValueRef* exception)
461 PrivateObject* privateObject = static_cast<PrivateObject*>(JSObjectGetPrivate(thisObject));
462 if (!privateObject) {
463 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch error");
466 JSContextRef globalContext = privateObject->getContext();
467 JSCallbackManagerPtr cbm = JSCallbackManager::createObject(globalContext);
470 JSValueRef reserveArguments[4];
472 AceSecurityStatus status = FILESYSTEM_CHECK_ACCESS(FILESYSTEM_FUNCTION_API_OPEN_STREAM);
473 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
478 for (index = 0; index < 4; index++) {
479 if (index < argumentCount)
480 reserveArguments[index] = arguments[index];
482 reserveArguments[index] = JSValueMakeUndefined(context);
486 JSValueRef onSuccess = getFunction(globalContext, reserveArguments[1]);
487 JSValueRef onError = NULL;
489 onError = getFunctionOrNull(globalContext, reserveArguments[2]);
491 cbm->setOnSuccess(onSuccess);
492 cbm->setOnError(onError);
493 cbm->setObject(thisObject);
496 Converter converter(globalContext);
498 AccessMode mode = converter.toAccessMode(reserveArguments[0]);
499 std::string encoding = Encodings::UTF8;
500 if (argumentCount > 3) {
501 if(!JSValueIsNull(globalContext, reserveArguments[3]) && !JSValueIsUndefined(globalContext, reserveArguments[3])){
502 encoding = converter.toEncoding(reserveArguments[3]);
506 if ((AM_READ != mode) && (PERM_READ == privateObject->getObject()->getNode()->getPermissions())) {
507 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::PERMISSION_DENIED_ERROR, "Permission denied error");
510 std::string path = privateObject->getObject()->getNode()->getPath()->getFullPath();
511 std::string vpath = Utils::toVirtualPath(globalContext, path);
513 AccessModeInfo am = AccessModeInfo(mode, vpath);
514 status = FILESYSTEM_ACCESSMODE_CHECK_ACCESS(FILESYSTEM_FUNCTION_API_OPEN_STREAM, am);
516 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
518 EventOpenPtr event(new EventOpen(mode));
519 event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData>(cbm));
520 event->setCharSet(encoding);
521 event->setForAsynchronousCall(&ResponseDispatcher::getInstance());
522 FilesystemAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
524 privateObject->getObject()->getNode()->open(event);
527 } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
528 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, ex.GetMessage());
529 } catch (const WrtDeviceApis::Commons::UnsupportedException& ex) {
530 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, ex.GetMessage());
531 } catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
532 cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, ex.GetMessage()));
533 } catch(const WrtDeviceApis::Commons::Exception& ex) {
534 cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, ex.GetMessage()));
537 return JSValueMakeUndefined(context);
540 JSValueRef JSFile::readAsText(JSContextRef context,
542 JSObjectRef thisObject,
544 const JSValueRef argv[],
545 JSValueRef* exception)
547 PrivateObject* privateObject = static_cast<PrivateObject*>(JSObjectGetPrivate(thisObject));
548 if (!privateObject) {
549 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch error");
553 JSContextRef globalContext = privateObject->getContext();
554 AceSecurityStatus status = FILESYSTEM_CHECK_ACCESS(FILESYSTEM_FUNCTION_API_READ_AS_TEXT);
555 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
558 JSValueRef reserveArguments[3];
559 JSCallbackManagerPtr cbm = JSCallbackManager::createObject(globalContext);
563 for (index = 0; index < 3; index++) {
565 reserveArguments[index] = argv[index];
567 reserveArguments[index] = JSValueMakeUndefined(context);
572 JSValueRef onSuccess = getFunction(globalContext, reserveArguments[0]);
573 JSValueRef onError = NULL;
576 onError = getFunctionOrNull(globalContext, reserveArguments[1]);
579 cbm->setOnSuccess(onSuccess);
580 cbm->setOnError(onError);
581 cbm->setObject(thisObject);
583 Converter converter(context);
584 std::string src = Encodings::UTF8;
586 if (!JSValueIsNull(context, reserveArguments[2]) && !JSValueIsUndefined(context, reserveArguments[2])) {
587 src = converter.toEncoding(reserveArguments[2]);
591 if (NT_FILE != privateObject->getObject()->getNode()->getType()) {
592 cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::IO_ERROR, "IO error"));
593 return JSValueMakeUndefined(context);
596 EventReadTextPtr event(new EventReadText());
597 event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData,JSCallbackManager>(cbm));
598 event->setCharSet(src);
599 event->setForAsynchronousCall(&ResponseDispatcher::getInstance());
600 FilesystemAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
602 privateObject->getObject()->getNode()->read(event);
604 } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
605 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, ex.GetMessage());
606 } catch (const WrtDeviceApis::Commons::UnsupportedException& ex) {
607 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, ex.GetMessage());
608 } catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
609 cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, ex.GetMessage()));
610 } catch(const WrtDeviceApis::Commons::Exception& ex) {
611 cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, ex.GetMessage()));
614 return JSValueMakeUndefined(context);
617 JSValueRef JSFile::copyTo(JSContextRef context,
619 JSObjectRef thisObject,
621 const JSValueRef argv[],
622 JSValueRef* exception)
624 PrivateObject* privateObject = static_cast<PrivateObject*>(JSObjectGetPrivate(thisObject));
625 if (!privateObject) {
626 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch error");
629 JSContextRef globalContext = privateObject->getContext();
631 JSValueRef reserveArguments[5];
632 JSCallbackManagerPtr cbm = JSCallbackManager::createObject(globalContext);
634 AceSecurityStatus status = FILESYSTEM_CHECK_ACCESS(FILESYSTEM_FUNCTION_API_COPY_TO);
635 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
640 for (index = 0; index < 5; index++)
643 reserveArguments[index] = argv[index];
645 reserveArguments[index] = JSValueMakeUndefined(context);
648 Converter converter(globalContext);
649 JSValueRef onSuccess = NULL;
650 JSValueRef onError = NULL;
652 onSuccess = getFunctionOrNull(globalContext, reserveArguments[3]);
653 onError = getFunctionOrNull(globalContext, reserveArguments[4]);
655 cbm->setOnSuccess(onSuccess);
656 cbm->setOnError(onError);
657 cbm->setObject(thisObject);
660 //TODO add check validation for src, dest string.
661 IPathPtr src = Utils::fromVirtualPath(globalContext, converter.toString(reserveArguments[0]));
662 IPathPtr dest = Utils::fromVirtualPath(globalContext, converter.toString(reserveArguments[1]));
663 bool overwrite = converter.toBool(reserveArguments[2]);;
665 if (NT_DIRECTORY != privateObject->getObject()->getNode()->getType()) {
666 cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::IO_ERROR, "IO error"));
667 return JSValueMakeUndefined(context);
670 std::string virtualDestPath = Utils::toVirtualPath(globalContext, dest->getFullPath());
671 AccessModeInfo amode = AccessModeInfo(AM_WRITE, virtualDestPath);
672 status = FILESYSTEM_ACCESSMODE_CHECK_ACCESS(
673 FILESYSTEM_FUNCTION_API_COPY_TO,
676 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
678 EventCopyPtr event(new EventCopy(src, dest));
681 event->setOptions(OPT_OVERWRITE);
684 event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::
688 event->setForAsynchronousCall(&ResponseDispatcher::getInstance());
689 FilesystemAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
691 IManager::getInstance().copy(event);
692 } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
693 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, ex.GetMessage());
694 } catch (const WrtDeviceApis::Commons::UnsupportedException& ex) {
695 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, ex.GetMessage());
696 } catch(const WrtDeviceApis::Commons::NotFoundException &ex) {
697 cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::NOT_FOUND_ERROR, ex.GetMessage()));
698 } catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
699 cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, ex.GetMessage()));
700 } catch(const WrtDeviceApis::Commons::Exception& ex) {
701 cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, ex.GetMessage()));
704 return JSValueMakeUndefined(context);
707 JSValueRef JSFile::moveTo(JSContextRef context,
709 JSObjectRef thisObject,
711 const JSValueRef argv[],
712 JSValueRef* exception)
714 PrivateObject* privateObject = static_cast<PrivateObject*>(JSObjectGetPrivate(thisObject));
715 if (!privateObject) {
716 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch error");
719 JSContextRef globalContext = privateObject->getContext();
724 JSValueRef reserveArguments[5];
725 JSCallbackManagerPtr cbm = JSCallbackManager::createObject(globalContext);
727 AceSecurityStatus status = FILESYSTEM_CHECK_ACCESS(FILESYSTEM_FUNCTION_API_MOVE_TO);
728 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
732 for (index = 0; index < 5; index++) {
734 reserveArguments[index] = argv[index];
736 reserveArguments[index] = JSValueMakeUndefined(context);
739 if ((privateObject->getObject()->getNode()->getPermissions() & PERM_WRITE) == 0) {
740 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::PERMISSION_DENIED_ERROR, "Permission denied error");
743 Converter converter(context);
744 JSValueRef onSuccess = NULL;
745 JSValueRef onError = NULL;
747 onSuccess = getFunctionOrNull(globalContext, reserveArguments[3]);
748 onError = getFunctionOrNull(globalContext, reserveArguments[4]);
749 cbm->setOnSuccess(onSuccess);
750 cbm->setOnError(onError);
751 cbm->setObject(thisObject);
753 if (NT_DIRECTORY != privateObject->getObject()->getNode()->getType()) {
754 cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::IO_ERROR, "io error"));
755 return JSValueMakeUndefined(context);
758 IPathPtr src = Utils::fromVirtualPath(globalContext, converter.toString(reserveArguments[0]));
759 IPathPtr dest = Utils::fromVirtualPath(globalContext, converter.toString(reserveArguments[1]));
760 bool overwrite = converter.toBool(reserveArguments[2]);
762 std::string virtualDestPath = Utils::toVirtualPath(globalContext, dest->getFullPath());
764 AccessModeInfo amode = AccessModeInfo(AM_WRITE, virtualDestPath);
765 AceSecurityStatus status = FILESYSTEM_ACCESSMODE_CHECK_ACCESS(FILESYSTEM_FUNCTION_API_MOVE_TO, amode);
767 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
769 EventMovePtr event(new EventMove(src, dest));
771 event->setOptions(OPT_OVERWRITE);
774 event->setForAsynchronousCall(&ResponseDispatcher::getInstance());
775 event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData > (cbm));
776 FilesystemAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
778 IManager::getInstance().move(event);
780 } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
781 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, ex.GetMessage());
782 } catch (const WrtDeviceApis::Commons::UnsupportedException& ex) {
783 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, ex.GetMessage());
784 } catch(const WrtDeviceApis::Commons::NotFoundException &ex) {
785 cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::NOT_FOUND_ERROR, ex.GetMessage()));
787 catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
788 cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, ex.GetMessage()));
789 } catch(const WrtDeviceApis::Commons::Exception& ex) {
790 cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, ex.GetMessage()));
792 return JSValueMakeUndefined(context);
795 JSValueRef JSFile::createDirectory(JSContextRef context,
797 JSObjectRef thisObject,
799 const JSValueRef argv[],
800 JSValueRef* exception)
802 PrivateObject* privateObject = static_cast<PrivateObject*>(JSObjectGetPrivate(thisObject));
803 if (!privateObject) {
804 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch error");
807 AceSecurityStatus status = FILESYSTEM_CHECK_ACCESS(FILESYSTEM_FUNCTION_API_CREATE_DIR);
808 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
811 Converter converter(context);
815 ThrowMsg(InvalidArgumentException, "Invalid path name");
818 IPathPtr path = converter.toPath(argv[0]);
819 INodePtr node(privateObject->getObject()->getNode()->createChild(path, NT_DIRECTORY, OPT_RECURSIVE));
820 node->setPermissions(privateObject->getObject()->getNode()->getPermissions());
822 PrivateObjectDefPtr privData(new PrivateObjectDef(node, privateObject->getObject()->getParentPermissions()));
823 privData->pushParentPermissions(privateObject->getObject()->getNode()->getPermissions());
825 return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(privateObject->getContext(), getClassRef(), privData);
826 } catch (const WrtDeviceApis::Commons::PlatformException& ex) {
827 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::IO_ERROR, ex.GetMessage());
828 } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
829 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, ex.GetMessage());
830 } catch (const WrtDeviceApis::Commons::UnsupportedException& ex) {
831 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, ex.GetMessage());
832 } catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
833 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, ex.GetMessage());
834 } catch(const WrtDeviceApis::Commons::Exception& ex) {
835 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, ex.GetMessage());
839 JSValueRef JSFile::createFile(JSContextRef context,
841 JSObjectRef thisObject,
843 const JSValueRef argv[],
844 JSValueRef* exception)
846 PrivateObject* privateObject = static_cast<PrivateObject*>(JSObjectGetPrivate(thisObject));
847 if (!privateObject) {
848 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch error");
851 AceSecurityStatus status = FILESYSTEM_CHECK_ACCESS(FILESYSTEM_FUNCTION_API_CREATE_FILE);
852 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
855 Converter converter(context);
859 ThrowMsg(InvalidArgumentException, "Invalid path name");
862 IPathPtr path = converter.toPath(argv[0]);
863 INodePtr node = privateObject->getObject()->getNode()->createChild(path, NT_FILE);
865 PrivateObjectDefPtr privData(new PrivateObjectDef(node, privateObject->getObject()->getParentPermissions()));
866 privData->pushParentPermissions(privateObject->getObject()->getNode()->getPermissions());
868 return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(privateObject->getContext(), getClassRef(), privData);
870 IPathPtr path = converter.toPath(argv[0]);
871 INodePtr node = privateObject->getObject()->getNode()->createChild(path, NT_FILE);
872 return JSUtils::makeObject(privateObject->getContext(), getClassRef(), node);*/
873 } catch (const WrtDeviceApis::Commons::PlatformException& ex) {
874 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::IO_ERROR, ex.GetMessage());
875 } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
876 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, ex.GetMessage());
877 } catch (const WrtDeviceApis::Commons::UnsupportedException& ex) {
878 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, ex.GetMessage());
879 } catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
880 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, ex.GetMessage());
881 } catch(const WrtDeviceApis::Commons::Exception& ex) {
882 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, ex.GetMessage());
887 JSValueRef JSFile::resolve(JSContextRef context,
889 JSObjectRef thisObject,
891 const JSValueRef argv[],
892 JSValueRef* exception)
894 PrivateObject* privateObject = static_cast<PrivateObject*>(JSObjectGetPrivate(thisObject));
895 if (!privateObject) {
896 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch error");
899 AceSecurityStatus status = FILESYSTEM_CHECK_ACCESS(FILESYSTEM_FUNCTION_API_RESOLVE);
900 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
902 if (privateObject->getObject()->getNode()->getType() != NT_DIRECTORY) {
903 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::IO_ERROR, "IO error");
906 Converter converter(context);
916 ThrowMsg(InvalidArgumentException, "Invalid path name");
922 IPathPtr path = converter.toPath(argv[0]);
923 INodePtr node = privateObject->getObject()->getNode()->getChild(path);
924 node->setPermissions(privateObject->getObject()->getNode()->getPermissions());
925 PrivateObjectDefPtr privData(new PrivateObjectDef(node, privateObject->getObject()->getParentPermissions()));
926 privData->pushParentPermissions(privateObject->getObject()->getNode()->getPermissions());
927 return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(privateObject->getContext(), getClassRef(), privData);
929 IPathPtr path = converter.toPath(argv[0]);
930 INodePtr node = privateObject->getObject()->getNode()->getChild(path);
931 node->setPermissions(privateObject->getObject()->getNode()->getPermissions());
932 return JSUtils::makeObject(privateObject->getContext(), getClassRef(), node);
934 } catch (const WrtDeviceApis::Commons::PlatformException& ex) {
935 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::IO_ERROR, ex.GetMessage());
936 } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
937 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, ex.GetMessage());
938 } catch (const WrtDeviceApis::Commons::UnsupportedException& ex) {
939 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, ex.GetMessage());
940 } catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
941 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, ex.GetMessage());
942 } catch(const WrtDeviceApis::Commons::NotFoundException& ex) {
943 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, ex.GetMessage());
944 } catch(const WrtDeviceApis::Commons::Exception& ex) {
945 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, ex.GetMessage());
949 JSValueRef JSFile::deleteDirectory(JSContextRef context,
951 JSObjectRef thisObject,
953 const JSValueRef argv[],
954 JSValueRef* exception)
956 PrivateObject* privateObject = static_cast<PrivateObject*>(JSObjectGetPrivate(thisObject));
957 if (!privateObject) {
958 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch error");
961 AceSecurityStatus status = FILESYSTEM_CHECK_ACCESS(FILESYSTEM_FUNCTION_API_DELETE_DIR);
962 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
965 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type missmatch error");
968 JSContextRef globalContext = privateObject->getContext();
973 JSValueRef reserveArguments[4];
974 JSCallbackManagerPtr cbm = JSCallbackManager::createObject(globalContext);
980 for (index = 0; index < 4; index++) {
982 reserveArguments[index] = argv[index];
984 reserveArguments[index] = JSValueMakeUndefined(context);
988 JSValueRef onSuccess = NULL;
989 JSValueRef onError = NULL;
991 onSuccess = getFunctionOrNull(globalContext, reserveArguments[2]);
992 onError = getFunctionOrNull(globalContext, reserveArguments[3]);
994 cbm->setOnSuccess(onSuccess);
995 cbm->setOnError(onError);
996 cbm->setObject(thisObject);
998 if ((privateObject->getObject()->getNode()->getPermissions() & PERM_WRITE) == 0) {
999 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::PERMISSION_DENIED_ERROR, "Permission denied error");
1002 if (privateObject->getObject()->getNode()->getType() != NT_DIRECTORY) {
1003 cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::IO_ERROR, "IO error"));
1004 return JSValueMakeUndefined(context);
1007 Converter converter(context);
1008 IPathPtr path = Utils::fromVirtualPath(globalContext, converter.toString(reserveArguments[0]));
1009 bool recursive = converter.toBool(reserveArguments[1]);
1011 if (*privateObject->getObject()->getNode()->getPath() != path->getPath()) {
1012 cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::NOT_FOUND_ERROR, "not found error"));
1013 return JSValueMakeUndefined(context);
1017 EventResolvePtr eventResolve(new EventResolve(path));
1018 if (eventResolve->setForSynchronousCall()) {
1019 IManager::getInstance().getNode(eventResolve);
1020 if (!eventResolve->getResult() || (eventResolve->getExceptionCode() != WrtDeviceApis::Commons::ExceptionCodes::None)) {
1022 if(eventResolve->getExceptionCode() == WrtDeviceApis::Commons::ExceptionCodes::NotFoundException)
1023 ThrowMsg(NotFoundException, "Not found error");
1025 ThrowMsg(PlatformException, "IO Error");
1028 if (eventResolve->getResult()->getType() != NT_DIRECTORY) {
1029 ThrowMsg(InvalidArgumentException, "Invalid directory");
1032 EventRemovePtr eventRemove(new EventRemove(path));
1035 eventRemove->setOptions(OPT_RECURSIVE);
1038 eventRemove->setForAsynchronousCall(&ResponseDispatcher::getInstance());
1039 eventRemove->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData > (cbm));
1040 FilesystemAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
1042 IManager::getInstance().remove(eventRemove);
1044 } catch (const WrtDeviceApis::Commons::PlatformException& ex) {
1045 cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::IO_ERROR, ex.GetMessage()));
1047 } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
1048 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, ex.GetMessage());
1049 } catch (const WrtDeviceApis::Commons::UnsupportedException& ex) {
1050 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, ex.GetMessage());
1051 } catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
1052 cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, ex.GetMessage()));
1053 } catch(const WrtDeviceApis::Commons::NotFoundException& ex) {
1054 cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::NOT_FOUND_ERROR, ex.GetMessage()));
1055 } catch(const WrtDeviceApis::Commons::Exception& ex) {
1056 cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, ex.GetMessage()));
1059 return JSValueMakeUndefined(context);
1062 JSValueRef JSFile::deleteFile(JSContextRef context,
1064 JSObjectRef thisObject,
1066 const JSValueRef argv[],
1067 JSValueRef* exception)
1071 PrivateObject* privateObject = static_cast<PrivateObject*>(JSObjectGetPrivate(thisObject));
1073 if (!privateObject) {
1074 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch error");
1077 JSContextRef globalContext = privateObject->getContext();
1080 JSValueRef reserveArguments[3];
1081 JSCallbackManagerPtr cbm = JSCallbackManager::createObject(globalContext);
1083 AceSecurityStatus status = FILESYSTEM_CHECK_ACCESS(FILESYSTEM_FUNCTION_API_DELETE_FILE);
1084 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
1088 for (index = 0; index < 3; index++) {
1090 reserveArguments[index] = argv[index];
1092 reserveArguments[index] = JSValueMakeUndefined(context);
1096 if ((privateObject->getObject()->getNode()->getPermissions() & PERM_WRITE) == 0) {
1097 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::PERMISSION_DENIED_ERROR, "Permission denied error");
1100 JSValueRef onSuccess = NULL;
1101 JSValueRef onError = NULL;
1103 onSuccess = getFunctionOrNull(globalContext, reserveArguments[1]);
1104 onError = getFunctionOrNull(globalContext, reserveArguments[2]);
1106 cbm->setOnSuccess(onSuccess);
1107 cbm->setOnError(onError);
1108 cbm->setObject(thisObject);
1110 if (privateObject->getObject()->getNode()->getType() != NT_DIRECTORY) {
1111 cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::IO_ERROR, "IO error"));
1112 return JSValueMakeUndefined(context);
1116 Converter converter(context);
1117 IPathPtr path = Utils::fromVirtualPath(globalContext, converter.toString(reserveArguments[0]));
1119 EventResolvePtr eventResolve(new EventResolve(path));
1120 if (eventResolve->setForSynchronousCall()) {
1121 IManager::getInstance().getNode(eventResolve);
1123 if (!eventResolve->getResult() ||(eventResolve->getExceptionCode() != WrtDeviceApis::Commons::ExceptionCodes::None)) {
1124 if(eventResolve->getExceptionCode() == WrtDeviceApis::Commons::ExceptionCodes::NotFoundException){
1125 LogDebug("POST IO NOT_FOUND_ERROR");
1126 ThrowMsg(NotFoundException, "Not found error");
1129 LogDebug("POST IO ERROR");
1130 cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::IO_ERROR, "IO error"));
1131 return JSValueMakeUndefined(context);
1134 if (eventResolve->getResult()->getType() != NT_FILE) {
1135 ThrowMsg(InvalidArgumentException, "Invalid directory");
1138 LogDebug("try to call async event");
1139 EventRemovePtr eventRemove(new EventRemove(path));
1140 eventRemove->setForAsynchronousCall(&ResponseDispatcher::getInstance());
1141 eventRemove->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData > (cbm));
1142 FilesystemAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
1144 IManager::getInstance().remove(eventRemove);
1147 } catch (const WrtDeviceApis::Commons::PlatformException& ex) {
1148 LogDebug("Platform Exception !!!!!!!! post io error");
1149 cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::IO_ERROR, ex.GetMessage()));
1150 } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
1151 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, ex.GetMessage());
1152 } catch (const WrtDeviceApis::Commons::UnsupportedException& ex) {
1153 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, ex.GetMessage());
1154 } catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
1155 cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, ex.GetMessage()));
1156 } catch(const WrtDeviceApis::Commons::NotFoundException& ex) {
1157 cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::NOT_FOUND_ERROR, ex.GetMessage()));
1158 } catch(const WrtDeviceApis::Commons::Exception& ex) {
1159 cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, ex.GetMessage()));
1163 return JSValueMakeUndefined(context);