2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 * @file FIoDirectory.cpp
19 * @brief This is the implementation file for Directory class.
23 #include <unique_ptr.h>
25 #include <FIoDirectory.h>
26 #include <FBaseSysLog.h>
28 #include <FBase_NativeError.h>
29 #include <FIo_DirectoryImpl.h>
31 using namespace Tizen::Base;
33 namespace Tizen { namespace Io
36 Directory::Directory(void)
37 : __pDirectoryImpl(null)
41 Directory::~Directory(void)
43 delete __pDirectoryImpl;
47 Directory::Construct(const String& dirPath)
51 SysTryReturnResult(NID_IO, dirPath.GetLength() > 0 && dirPath.GetLength() <= PATH_MAX, E_INVALID_ARG,
52 ("Given directory name length is not correct!"));
54 SysAssertf(__pDirectoryImpl == null, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
56 std::unique_ptr<_DirectoryImpl> pDirectoryImpl(new (std::nothrow) _DirectoryImpl);
57 SysTryReturnResult(NID_IO, pDirectoryImpl != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
59 r = pDirectoryImpl->Construct(dirPath);
60 SysTryReturn(NID_IO, !IsFailed(r), r, r, "[%s] Propagated.", GetErrorMessage(r));
62 __pDirectoryImpl = pDirectoryImpl.release();
68 Directory::ReadN(void)
70 SysAssertf(__pDirectoryImpl != null, "Not yet constructed. Construct() should be called before use.\n");
71 return __pDirectoryImpl->ReadN();
75 Directory::Create(const String& dirPath, bool createParentDirsToo)
77 SysTryReturnResult(NID_IO, dirPath.GetLength() > 0 && dirPath.GetLength() <= PATH_MAX, E_INVALID_ARG,
78 ("Given directory name length is not correct!"));
79 return _DirectoryImpl::Create(dirPath, createParentDirsToo);
83 Directory::Remove(const String& dirPath, bool recursive)
85 SysTryReturnResult(NID_IO, dirPath.GetLength() > 0 && dirPath.GetLength() <= PATH_MAX, E_INVALID_ARG,
86 ("Given file name length is not correct!"));
87 return _DirectoryImpl::Remove(dirPath, recursive);
91 Directory::Rename(const String& orgDirPath, const String& newDirPath)
93 SysTryReturnResult(NID_IO, orgDirPath.GetLength() > 0 && orgDirPath.GetLength() <= PATH_MAX, E_INVALID_ARG,
94 ("Given file name length is not correct!"));
95 SysTryReturnResult(NID_IO, newDirPath.GetLength() > 0 && newDirPath.GetLength() <= PATH_MAX, E_INVALID_ARG,
96 ("Given file name length is not correct!"));
97 return _DirectoryImpl::Rename(orgDirPath, newDirPath);