2 // Open Service Platform
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.
19 * @file FIoDirectory.cpp
20 * @brief This is the implementation file for Directory class.
24 #include <unique_ptr.h>
26 #include <FIoDirectory.h>
27 #include <FBaseSysLog.h>
29 #include <FBase_NativeError.h>
30 #include <FIo_DirectoryImpl.h>
32 using namespace Tizen::Base;
34 namespace Tizen { namespace Io
37 Directory::Directory(void)
38 : __pDirectoryImpl(null)
42 Directory::~Directory(void)
44 delete __pDirectoryImpl;
48 Directory::Construct(const String& dirPath)
52 SysTryReturnResult(NID_IO, dirPath.GetLength() > 0 && dirPath.GetLength() <= PATH_MAX, E_INVALID_ARG,
53 ("Given directory name length is not correct!"));
55 SysAssertf(__pDirectoryImpl == null, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
57 std::unique_ptr<_DirectoryImpl> pDirectoryImpl(new (std::nothrow) _DirectoryImpl);
58 SysTryReturnResult(NID_IO, pDirectoryImpl != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
60 r = pDirectoryImpl->Construct(dirPath);
61 SysTryReturn(NID_IO, !IsFailed(r), r, r, "[%s] Propagated.", GetErrorMessage(r));
63 __pDirectoryImpl = pDirectoryImpl.release();
69 Directory::ReadN(void)
71 SysAssertf(__pDirectoryImpl != null, "Not yet constructed. Construct() should be called before use.\n");
72 return __pDirectoryImpl->ReadN();
76 Directory::Create(const String& dirPath, bool createParentDirsToo)
78 SysTryReturnResult(NID_IO, dirPath.GetLength() > 0 && dirPath.GetLength() <= PATH_MAX, E_INVALID_ARG,
79 ("Given directory name length is not correct!"));
80 return _DirectoryImpl::Create(dirPath, createParentDirsToo);
84 Directory::Remove(const String& dirPath, bool recursive)
86 SysTryReturnResult(NID_IO, dirPath.GetLength() > 0 && dirPath.GetLength() <= PATH_MAX, E_INVALID_ARG,
87 ("Given file name length is not correct!"));
88 return _DirectoryImpl::Remove(dirPath, recursive);
92 Directory::Rename(const String& orgDirPath, const String& newDirPath)
94 SysTryReturnResult(NID_IO, orgDirPath.GetLength() > 0 && orgDirPath.GetLength() <= PATH_MAX, E_INVALID_ARG,
95 ("Given file name length is not correct!"));
96 SysTryReturnResult(NID_IO, newDirPath.GetLength() > 0 && newDirPath.GetLength() <= PATH_MAX, E_INVALID_ARG,
97 ("Given file name length is not correct!"));
98 return _DirectoryImpl::Rename(orgDirPath, newDirPath);