[gnote] Make directory_get_directories return



commit 4253f115efb9432283aee5d5fd57b47f2d98bbbf
Author: Aurimas Černius <aurisc4 gmail com>
Date:   Sat Apr 13 14:01:53 2019 +0300

    Make directory_get_directories return

 src/sharp/directory.cpp                      | 11 ++++++-----
 src/sharp/directory.hpp                      |  3 +--
 src/synchronization/filesystemsyncserver.cpp |  8 +++-----
 src/test/unit/directorytests.cpp             | 15 +++++----------
 4 files changed, 15 insertions(+), 22 deletions(-)
---
diff --git a/src/sharp/directory.cpp b/src/sharp/directory.cpp
index 78857a75..9b2d971e 100644
--- a/src/sharp/directory.cpp
+++ b/src/sharp/directory.cpp
@@ -114,11 +114,11 @@ namespace sharp {
     }
   }
 
-  void directory_get_directories(const Glib::RefPtr<Gio::File> & dir,
-                                 std::vector<Glib::RefPtr<Gio::File>> & files)
+  std::vector<Glib::RefPtr<Gio::File>> directory_get_directories(const Glib::RefPtr<Gio::File> & dir)
   {
+    std::vector<Glib::RefPtr<Gio::File>> files;
     if(!directory_exists(dir)) {
-      return;
+      return files;
     }
 
     auto children = dir->enumerate_children();
@@ -132,6 +132,8 @@ namespace sharp {
         files.push_back(child);
       }
     }
+
+    return files;
   }
 
   void directory_get_files(const Glib::ustring & dir, std::list<Glib::ustring> & files)
@@ -235,8 +237,7 @@ namespace sharp {
           return false;
         }
       }
-      files.clear();
-      directory_get_directories(dir, files);
+      files = directory_get_directories(dir);
       for(auto d : files) {
         if(!directory_delete(d, true)) {
           ERR_OUT("Failed to remove directory %s", d->get_uri().c_str());
diff --git a/src/sharp/directory.hpp b/src/sharp/directory.hpp
index 26024a86..00551801 100644
--- a/src/sharp/directory.hpp
+++ b/src/sharp/directory.hpp
@@ -49,8 +49,7 @@ namespace sharp {
 
   void directory_get_directories(const Glib::ustring & dir,
                                  std::list<Glib::ustring> & files);
-  void directory_get_directories(const Glib::RefPtr<Gio::File> & dir,
-                                 std::vector<Glib::RefPtr<Gio::File>> & files);
+  std::vector<Glib::RefPtr<Gio::File>> directory_get_directories(const Glib::RefPtr<Gio::File> & dir);
 
   void directory_get_files(const Glib::ustring & dir,
                            std::list<Glib::ustring> & files);
diff --git a/src/synchronization/filesystemsyncserver.cpp b/src/synchronization/filesystemsyncserver.cpp
index 7b7456c2..2e02664b 100644
--- a/src/synchronization/filesystemsyncserver.cpp
+++ b/src/synchronization/filesystemsyncserver.cpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2012-2013,2017-2018 Aurimas Cernius
+ * Copyright (C) 2012-2013,2017-2019 Aurimas Cernius
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -418,8 +418,7 @@ int FileSystemSyncServer::latest_revision()
   while (!foundValidManifest) {
     if(latestRev < 0) {
       // Look for the highest revision parent path
-      std::vector<Glib::RefPtr<Gio::File>> directories;
-      sharp::directory_get_directories(m_server_path, directories);
+      std::vector<Glib::RefPtr<Gio::File>> directories = sharp::directory_get_directories(m_server_path);
       for(auto & iter : directories) {
         try {
           int currentRevParentDir = str_to_int(sharp::file_filename(iter));
@@ -432,8 +431,7 @@ int FileSystemSyncServer::latest_revision()
       }
 
       if(latestRevDir >= 0) {
-        directories.clear();
-        sharp::directory_get_directories(m_server_path->get_child(TO_STRING(latestRevDir)), directories);
+        directories = sharp::directory_get_directories(m_server_path->get_child(TO_STRING(latestRevDir)));
         for(auto & iter : directories) {
           try {
             int currentRev = str_to_int(iter->get_basename());
diff --git a/src/test/unit/directorytests.cpp b/src/test/unit/directorytests.cpp
index 230e3418..08479e7b 100644
--- a/src/test/unit/directorytests.cpp
+++ b/src/test/unit/directorytests.cpp
@@ -40,8 +40,7 @@ SUITE(directory)
   {
     auto dir = Gio::File::create_for_path(Glib::build_filename(Glib::path_get_dirname(__FILE__), 
"nonexistent"));
 
-    std::vector<Glib::RefPtr<Gio::File>> directories;
-    sharp::directory_get_directories(dir, directories);
+    std::vector<Glib::RefPtr<Gio::File>> directories = sharp::directory_get_directories(dir);
     CHECK_EQUAL(0, directories.size());
   }
 
@@ -58,8 +57,7 @@ SUITE(directory)
   {
     auto dir = Gio::File::create_for_path(__FILE__);
 
-    std::vector<Glib::RefPtr<Gio::File>> directories;
-    sharp::directory_get_directories(dir, directories);
+    std::vector<Glib::RefPtr<Gio::File>> directories = sharp::directory_get_directories(dir);
     CHECK_EQUAL(0, directories.size());
   }
 
@@ -76,8 +74,7 @@ SUITE(directory)
   {
     auto dir = Gio::File::create_for_path(Glib::build_filename(Glib::path_get_dirname(__FILE__), ".deps"));
 
-    std::vector<Glib::RefPtr<Gio::File>> directories;
-    sharp::directory_get_directories(dir, directories);
+    std::vector<Glib::RefPtr<Gio::File>> directories = sharp::directory_get_directories(dir);
     CHECK_EQUAL(0, directories.size());
   }
 
@@ -94,8 +91,7 @@ SUITE(directory)
   {
     auto dir = Gio::File::create_for_path(Glib::path_get_dirname(__FILE__));
 
-    std::vector<Glib::RefPtr<Gio::File>> directories;
-    sharp::directory_get_directories(dir, directories);
+    std::vector<Glib::RefPtr<Gio::File>> directories = sharp::directory_get_directories(dir);
     CHECK_EQUAL(1, directories.size());
   }
 
@@ -122,8 +118,7 @@ SUITE(directory)
 
     auto file = Gio::File::create_for_path(dir);
 
-    std::vector<Glib::RefPtr<Gio::File>> dirsf;
-    sharp::directory_get_directories(file, dirsf);
+    std::vector<Glib::RefPtr<Gio::File>> dirsf = sharp::directory_get_directories(file);
 
     CHECK(0 < dirss.size());
     CHECK_EQUAL(dirss.size(), dirsf.size());


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]