diff options
author | An-Cheng Huang <ancheng@vyatta.com> | 2011-05-16 15:25:38 -0700 |
---|---|---|
committer | An-Cheng Huang <ancheng@vyatta.com> | 2011-05-16 15:25:38 -0700 |
commit | b4f5e830b6ad8237416198489cc8cc6142f4663d (patch) | |
tree | 1b2e1b79320c57f5301eb004b6c94af0d95bc357 | |
parent | e4fc18feef1f14e2e17208d303a388e758557f74 (diff) | |
download | vyatta-cfg-b4f5e830b6ad8237416198489cc8cc6142f4663d.tar.gz vyatta-cfg-b4f5e830b6ad8237416198489cc8cc6142f4663d.zip |
tweak directory handling for unionfs
-rw-r--r-- | src/cstore/unionfs/cstore-unionfs.cpp | 31 | ||||
-rw-r--r-- | src/cstore/unionfs/cstore-unionfs.hpp | 1 |
2 files changed, 27 insertions, 5 deletions
diff --git a/src/cstore/unionfs/cstore-unionfs.cpp b/src/cstore/unionfs/cstore-unionfs.cpp index ee24c46..6ccdbf2 100644 --- a/src/cstore/unionfs/cstore-unionfs.cpp +++ b/src/cstore/unionfs/cstore-unionfs.cpp @@ -659,9 +659,16 @@ UnionfsCstore::commitConfig(commit::PrioNode& node) if (!do_umount(work_root)) { return false; } - if (b_fs::remove_all(change_root.path_cstr()) < 1 - || b_fs::remove_all(active_root.path_cstr()) < 1) { - output_internal("failed to remove existing directories\n"); + if (b_fs::remove_all(change_root.path_cstr()) < 1) { + output_internal("failed to remove [%s]\n", change_root.path_cstr()); + return false; + } + /* note: unionfs can't cope with whole directory being removed, so just + * remove the content. + */ + if (!remove_dir_content(active_root.path_cstr())) { + output_internal("failed to remove [%s] content\n", + active_root.path_cstr()); return false; } try { @@ -680,13 +687,11 @@ UnionfsCstore::commitConfig(commit::PrioNode& node) if (!sync_dir(tmp_work_root, work_root, work_root)) { return false; } -#if 0 if (b_fs::remove_all(tmp_work_root.path_cstr()) < 1 || b_fs::remove_all(tmp_active_root.path_cstr()) < 1) { output_user("failed to remove temp directories\n"); return false; } -#endif // all done return true; } @@ -1500,6 +1505,22 @@ UnionfsCstore::path_is_regular(const char *path) return b_fs::is_regular(result); } +bool +UnionfsCstore::remove_dir_content(const char *path) +{ + if (!path_is_directory(path)) { + return false; + } + + b_fs::directory_iterator di(path); + for (; di != b_fs::directory_iterator(); ++di) { + if (b_fs::remove_all(di->path()) < 1) { + return false; + } + } + return true; +} + } // end namespace unionfs } // end namespace cstore diff --git a/src/cstore/unionfs/cstore-unionfs.hpp b/src/cstore/unionfs/cstore-unionfs.hpp index 8113d00..c7cd2d9 100644 --- a/src/cstore/unionfs/cstore-unionfs.hpp +++ b/src/cstore/unionfs/cstore-unionfs.hpp @@ -293,6 +293,7 @@ private: bool path_is_regular(const FsPath& path) { return path_is_regular(path.path_cstr()); }; + bool remove_dir_content(const char *path); }; } // end namespace unionfs |