This is an automated email from the git hooks/post-receive script.

guillem pushed a commit to branch master
in repository dpkg.

View the commit online:
https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=3d494a7ab27debd8842157c50c46d5bb49952671

commit 3d494a7ab27debd8842157c50c46d5bb49952671
Author: Guillem Jover <[email protected]>
AuthorDate: Fri Aug 31 01:49:20 2018 +0200

    libdpkg: Add new fsys-dir module
    
    This module handles setting and getting the filesystem root directory.
---
 debian/changelog                          |  1 +
 lib/dpkg/Makefile.am                      |  1 +
 lib/dpkg/{dbdir.c => fsys-dir.c}          | 55 +++++++++++++++++--------------
 lib/dpkg/fsys.h                           |  4 +++
 lib/dpkg/libdpkg.map                      |  4 +++
 lib/dpkg/t/.gitignore                     |  1 +
 lib/dpkg/t/Makefile.am                    |  1 +
 lib/dpkg/t/{t-pkg-show.c => t-fsys-dir.c} | 52 +++++++++++++++--------------
 po/POTFILES.in                            |  1 +
 9 files changed, 71 insertions(+), 49 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index eb68b75dc..6f9e4a0a6 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -27,6 +27,7 @@ dpkg (1.19.2) UNRELEASED; urgency=medium
     - Dpkg(1): Add POD documentation about the module hierarchy and API.
   * Code internals:
     - dpkg-split: Use nfstrnsave() instead of nfmalloc() + memcpy().
+    - libdpkg: Add new fsys-dir module.
   * Build system:
     - Distribute a LICENSE file on CPAN.
     - Do not make the Build.PL script executable.
diff --git a/lib/dpkg/Makefile.am b/lib/dpkg/Makefile.am
index 58bd403ab..a2828af4b 100644
--- a/lib/dpkg/Makefile.am
+++ b/lib/dpkg/Makefile.am
@@ -70,6 +70,7 @@ libdpkg_la_SOURCES = \
        fdio.c \
        file.c \
        fields.c \
+       fsys-dir.c\
        fsys-iter.c \
        fsys-hash.c \
        glob.c \
diff --git a/lib/dpkg/dbdir.c b/lib/dpkg/fsys-dir.c
similarity index 55%
copy from lib/dpkg/dbdir.c
copy to lib/dpkg/fsys-dir.c
index 2a0eefad8..15335b23e 100644
--- a/lib/dpkg/dbdir.c
+++ b/lib/dpkg/fsys-dir.c
@@ -1,8 +1,8 @@
 /*
  * libdpkg - Debian packaging suite library routines
- * dbdir.c - on-disk database directory functions
+ * fsys-dir.c - filesystem root directory functions
  *
- * Copyright © 2011 Guillem Jover <[email protected]>
+ * Copyright © 2011, 2018 Guillem Jover <[email protected]>
  *
  * This is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -21,58 +21,63 @@
 #include <config.h>
 #include <compat.h>
 
-#include <sys/types.h>
-
 #include <stdlib.h>
 
 #include <dpkg/dpkg.h>
-#include <dpkg/dpkg-db.h>
+#include <dpkg/string.h>
+#include <dpkg/path.h>
+#include <dpkg/fsys.h>
 
-static const char *db_dir = ADMINDIR;
+static const char *fsys_dir = "";
 
 /**
- * Set current on-disk database directory.
+ * Set current on-disk filesystem root directory.
  *
- * The directory is initially set to ADMINDIR, this function can be used to
+ * The directory is initially set to "", this function can be used to
  * set the directory to a new value, or to set it to a default value if dir
  * is NULL. For the latter the order is, value from environment variable
- * DPKG_ADMINDIR, and then the built-in default ADMINDIR,
+ * DPKG_ROOT, and then the built-in default "",
  *
- * @param dir The new database directory, or NULL to set to default.
+ * @param dir The new filesystem root directory, or NULL to set to default.
  *
- * @return The new database directory.
+ * @return The new filesystem root directory.
  */
 const char *
-dpkg_db_set_dir(const char *dir)
+dpkg_fsys_set_dir(const char *dir)
 {
+       char *new_dir;
+
        if (dir == NULL) {
                const char *env;
 
-               env = getenv("DPKG_ADMINDIR");
+               env = getenv("DPKG_ROOT");
                if (env)
-                       db_dir = env;
+                       dir = env;
                else
-                       db_dir = ADMINDIR;
-       } else {
-               db_dir = dir;
+                       dir = "";
        }
 
-       return db_dir;
+       new_dir = m_strdup(dir);
+       path_trim_slash_slashdot(new_dir);
+
+       fsys_dir = new_dir;
+
+       return fsys_dir;
 }
 
 /**
- * Get current on-disk database directory.
+ * Get current on-disk filesystem root directory.
  *
- * @return The current database directory.
+ * @return The current filesystem root directory.
  */
 const char *
-dpkg_db_get_dir(void)
+dpkg_fsys_get_dir(void)
 {
-       return db_dir;
+       return fsys_dir;
 }
 
 /**
- * Get a pathname to the current on-disk database directory.
+ * Get a pathname to the current on-disk filesystem root directory.
  *
  * This function returns an allocated string, which should be freed with
  * free(2).
@@ -82,7 +87,7 @@ dpkg_db_get_dir(void)
  * @return The newly allocated pathname.
  */
 char *
-dpkg_db_get_path(const char *pathpart)
+dpkg_fsys_get_path(const char *pathpart)
 {
-       return str_fmt("%s/%s", db_dir, pathpart);
+       return str_fmt("%s/%s", fsys_dir, pathpart);
 }
diff --git a/lib/dpkg/fsys.h b/lib/dpkg/fsys.h
index 8a2efbffa..72d76f715 100644
--- a/lib/dpkg/fsys.h
+++ b/lib/dpkg/fsys.h
@@ -190,4 +190,8 @@ struct filepackages_iterator *filepackages_iter_new(struct 
filenamenode *fnn);
 struct pkginfo *filepackages_iter_next(struct filepackages_iterator *iter);
 void filepackages_iter_free(struct filepackages_iterator *iter);
 
+const char *dpkg_fsys_set_dir(const char *dir);
+const char *dpkg_fsys_get_dir(void);
+char *dpkg_fsys_get_path(const char *pathpart);
+
 #endif /* LIBDPKG_FSYS_H */
diff --git a/lib/dpkg/libdpkg.map b/lib/dpkg/libdpkg.map
index cb3062845..082732405 100644
--- a/lib/dpkg/libdpkg.map
+++ b/lib/dpkg/libdpkg.map
@@ -419,6 +419,10 @@ LIBDPKG_PRIVATE {
        filepackages_iter_next;
        filepackages_iter_free;
 
+       dpkg_fsys_set_dir;
+       dpkg_fsys_get_dir;
+       dpkg_fsys_get_path;
+
        # Package on-disk filesystem database support
        parse_filehash;
        write_filelist_except;
diff --git a/lib/dpkg/t/.gitignore b/lib/dpkg/t/.gitignore
index db7126c04..5b019c86e 100644
--- a/lib/dpkg/t/.gitignore
+++ b/lib/dpkg/t/.gitignore
@@ -10,6 +10,7 @@ t-deb-version
 t-ehandle
 t-error
 t-file
+t-fsys-dir
 t-fsys-hash
 t-headers-cpp
 t-macros
diff --git a/lib/dpkg/t/Makefile.am b/lib/dpkg/t/Makefile.am
index 9e83836e4..83c96f329 100644
--- a/lib/dpkg/t/Makefile.am
+++ b/lib/dpkg/t/Makefile.am
@@ -48,6 +48,7 @@ test_programs = \
        t-pkg-queue \
        t-pkg-hash \
        t-pkg-show \
+       t-fsys-dir \
        t-fsys-hash \
        t-trigger \
        t-mod-db \
diff --git a/lib/dpkg/t/t-pkg-show.c b/lib/dpkg/t/t-fsys-dir.c
similarity index 53%
copy from lib/dpkg/t/t-pkg-show.c
copy to lib/dpkg/t/t-fsys-dir.c
index f5a978e81..7dbe753d1 100644
--- a/lib/dpkg/t/t-pkg-show.c
+++ b/lib/dpkg/t/t-fsys-dir.c
@@ -1,6 +1,6 @@
 /*
  * libdpkg - Debian packaging suite library routines
- * t-pkg-show.c - test pkg-show implementation
+ * t-fsys.c - test filesystem handling
  *
  * Copyright © 2018 Guillem Jover <[email protected]>
  *
@@ -21,41 +21,45 @@
 #include <config.h>
 #include <compat.h>
 
+#include <stdlib.h>
+
 #include <dpkg/test.h>
-#include <dpkg/dpkg-db.h>
-#include <dpkg/arch.h>
+#include <dpkg/fsys.h>
 
 static void
-test_pkg_show_name(void)
+test_fsys_dir(void)
 {
-       struct dpkg_arch *arch;
-       struct pkginfo *pkg;
-       const char *pkgname;
+       char *dir;
+
+       test_str(dpkg_fsys_get_dir(), ==, "");
+
+       dpkg_fsys_set_dir("/testdir");
+       test_str(dpkg_fsys_get_dir(), ==, "/testdir");
 
-       arch = dpkg_arch_find("arch");
-       test_pass(arch);
+       dir = dpkg_fsys_get_path("testfile");
+       test_str(dir, ==, "/testdir/testfile");
+       free(dir);
 
-       pkg = pkg_db_find_pkg("test", arch);
-       test_pass(pkg);
-       test_str(pkg->set->name, ==, "test");
-       test_pass(pkg->installed.arch->type == DPKG_ARCH_UNKNOWN);
+       setenv("DPKG_ROOT", "/testenvdir", 1);
+       dpkg_fsys_set_dir(NULL);
+       test_str(dpkg_fsys_get_dir(), ==, "/testenvdir");
 
-       pkgname = pkg_name(pkg, pnaw_never);
-       test_pass(pkgname);
-       test_str(pkgname, ==, "test");
+       dir = dpkg_fsys_get_path("testfile");
+       test_str(dir, ==, "/testenvdir/testfile");
+       free(dir);
 
-       pkgname = pkg_name(pkg, pnaw_nonambig);
-       test_pass(pkgname);
-       test_str(pkgname, ==, "test:arch");
+       unsetenv("DPKG_ROOT");
+       dpkg_fsys_set_dir(NULL);
+       test_str(dpkg_fsys_get_dir(), ==, "");
 
-       pkgname = pkg_name(pkg, pnaw_always);
-       test_pass(pkgname);
-       test_str(pkgname, ==, "test:arch");
+       dir = dpkg_fsys_get_path("testfile");
+       test_str(dir, ==, "/testfile");
+       free(dir);
 }
 
 TEST_ENTRY(test)
 {
-       test_plan(10);
+       test_plan(7);
 
-       test_pkg_show_name();
+       test_fsys_dir();
 }
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 43212d541..1fc14b9f6 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -28,6 +28,7 @@ lib/dpkg/error.c
 lib/dpkg/fdio.c
 lib/dpkg/fields.c
 lib/dpkg/file.c
+lib/dpkg/fsys-dir.c
 lib/dpkg/fsys-iter.c
 lib/dpkg/fsys-hash.c
 lib/dpkg/glob.c

-- 
Dpkg.Org's dpkg

Reply via email to