tizen 2.4 release
[framework/web/wrt-commons.git] / modules / utils / src / path.cpp
similarity index 93%
rename from modules_wearable/utils/src/path.cpp
rename to modules/utils/src/path.cpp
index 0a41837..4e831b8 100644 (file)
 
 #include "dpl/utils/path.h"
 #include <dpl/utils/wrt_utility.h>
-#include <dpl/scoped_free.h>
 #include <dpl/errno_string.h>
 #include <dpl/file_input.h>
 #include <dpl/file_output.h>
 #include <dpl/copy.h>
-#include <dpl/log/log.h>
+#include <dpl/log/wrt_log.h>
 #include <dpl/foreach.h>
 #include <dpl/wrt-dao-ro/global_config.h>
 
 #include <unistd.h>
 #include <ftw.h>
 #include <sys/time.h>
+#include <dpl/free_deleter.h>
+#include <memory>
 
 namespace DPL {
 
@@ -140,8 +141,8 @@ void Path::Construct(const std::string & src)
     if(src.empty()) ThrowMsg(EmptyPath, "Path cannot be empty");
     if(src[0] != '/')
     {
-        DPL::ScopedFree<char> root(getcwd(NULL,0));
-        Tokenize(std::string(root.Get()), "\\/", std::inserter(m_parts, m_parts.begin()), true);
+        std::unique_ptr<char[],free_deleter> root(getcwd(NULL,0));
+        Tokenize(std::string(root.get()), "\\/", std::inserter(m_parts, m_parts.begin()), true);
     }
     Tokenize(src, "\\/", std::inserter(m_parts, m_parts.end()), true);
 }
@@ -245,7 +246,7 @@ bool Path::ExistsAndIsFile() const
     {
         flag = this->IsFile();
     } Catch (Path::NotExists) {
-        LogPedantic(*this << "is not a file.");
+        WrtLogD("%s is not a file.", Fullpath().c_str());
     }
     return flag;
 }
@@ -257,7 +258,7 @@ bool Path::ExistsAndIsDir() const
     {
         flag = this->IsDir();
     } Catch (Path::NotExists) {
-        LogPedantic(*this << "is not a directory.");
+        WrtLogD("%s is not a directory.", Fullpath().c_str());
     }
     return flag;
 }
@@ -273,6 +274,16 @@ bool Path::IsSymlink() const
     return S_ISLNK(tmp.st_mode);
 }
 
+std::size_t Path::LastWriteTime() const
+{
+    struct stat st;
+    memset(&st, 0, sizeof(struct stat));
+    if (-1 == stat(Fullpath().c_str(), &st)) {
+        ThrowMsg(NotExists, DPL::GetErrnoString());
+    }
+    return st.st_mtime;
+}
+
 bool Path::operator==(const Path & other) const
 {
     return m_parts == other.m_parts;
@@ -363,7 +374,7 @@ bool Path::isSubPath(const Path & other) const
 
 bool Path::hasExtension(const std::string& extension) const
 {
-    LogPedantic("Looking for extension " << extension);
+    WrtLogD("Looking for extension %s", extension.c_str());
 
     if(Extension() == extension)
     {
@@ -458,17 +469,17 @@ void CopyFile(const Path & from, const Path & to)
     }
     Catch(DPL::FileInput::Exception::Base)
     {
-        LogError("File input error");
+        WrtLogE("File input error");
         ReThrowMsg(DPL::CopyFailed, std::string("File input error") + from.Fullpath());
     }
     Catch(DPL::FileOutput::Exception::Base)
     {
-        LogError("File output error");
+        WrtLogE("File output error");
         ReThrowMsg(DPL::CopyFailed, std::string("File output error") + to.Fullpath());
     }
     Catch(DPL::CopyFailed)
     {
-        LogError("File copy error");
+        WrtLogE("File copy error");
         ReThrowMsg(DPL::CopyFailed, std::string("File copy error") + from.Fullpath());
     }
 }
@@ -501,7 +512,7 @@ void CopyDir(const Path & from, const Path & to)
 
 Path CreateTempPath(const Path & basePath)
 {
-    LogDebug("Step: Creating temporary path");
+    WrtLogD("Step: Creating temporary path");
 
     // Temporary path
     Path tempPath = basePath;