Merge "Update deprecated libprivilege-control API functions." into tizen
[platform/framework/native/appfw.git] / src / io / FIoDirectory.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
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
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
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.
15 //
16
17 /**
18  * @file                FIoDirectory.cpp
19  * @brief               This is the implementation file for Directory class.
20  */
21
22 #include <limits.h>
23 #include <unique_ptr.h>
24
25 #include <FIoDirectory.h>
26 #include <FBaseSysLog.h>
27
28 #include <FBase_NativeError.h>
29 #include <FIo_DirectoryImpl.h>
30
31 using namespace Tizen::Base;
32
33 namespace Tizen { namespace Io
34 {
35
36 Directory::Directory(void)
37         : __pDirectoryImpl(null)
38 {
39 }
40
41 Directory::~Directory(void)
42 {
43         delete __pDirectoryImpl;
44 }
45
46 result
47 Directory::Construct(const String& dirPath)
48 {
49         result r = E_SUCCESS;
50
51         SysTryReturnResult(NID_IO, dirPath.GetLength() > 0 && dirPath.GetLength() <= PATH_MAX, E_INVALID_ARG,
52                            ("Given directory name length is not correct!"));
53
54         SysAssertf(__pDirectoryImpl == null, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
55
56         std::unique_ptr<_DirectoryImpl> pDirectoryImpl(new (std::nothrow) _DirectoryImpl);
57         SysTryReturnResult(NID_IO, pDirectoryImpl != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
58
59         r = pDirectoryImpl->Construct(dirPath);
60         SysTryReturn(NID_IO, !IsFailed(r), r, r, "[%s] Propagated.", GetErrorMessage(r));
61
62         __pDirectoryImpl = pDirectoryImpl.release();
63
64         return E_SUCCESS;
65 }
66
67 DirEnumerator*
68 Directory::ReadN(void)
69 {
70         SysAssertf(__pDirectoryImpl != null, "Not yet constructed. Construct() should be called before use.\n");
71         return __pDirectoryImpl->ReadN();
72 }
73
74 result
75 Directory::Create(const String& dirPath, bool createParentDirsToo)
76 {
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);
80 }
81
82 result
83 Directory::Remove(const String& dirPath, bool recursive)
84 {
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);
88 }
89
90 result
91 Directory::Rename(const String& orgDirPath, const String& newDirPath)
92 {
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);
98 }
99
100 }} // Tizen::Io
101