From 0709d31d5ef3ec19331abcd97545add26b7b0e13 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Sun, 24 Nov 2019 17:16:06 +0100 Subject: Cleanup: move canonicalize_name back to libfstree.a Signed-off-by: David Oberhollenzer --- difftool/Makemodule.am | 2 +- include/fstree.h | 9 +++++++ include/util/util.h | 9 ------- lib/fstree/Makemodule.am | 1 + lib/fstree/canonicalize_name.c | 60 +++++++++++++++++++++++++++++++++++++++++ lib/util/Makemodule.am | 3 +-- lib/util/canonicalize_name.c | 61 ------------------------------------------ tar/Makemodule.am | 4 +-- tests/Makemodule.am | 2 +- tests/canonicalize_name.c | 3 +-- unpack/Makemodule.am | 2 +- 11 files changed, 77 insertions(+), 79 deletions(-) create mode 100644 lib/fstree/canonicalize_name.c delete mode 100644 lib/util/canonicalize_name.c diff --git a/difftool/Makemodule.am b/difftool/Makemodule.am index e827a8b..7eb6600 100644 --- a/difftool/Makemodule.am +++ b/difftool/Makemodule.am @@ -2,6 +2,6 @@ sqfsdiff_SOURCES = difftool/sqfsdiff.c difftool/sqfsdiff.h difftool/util.c sqfsdiff_SOURCES += difftool/compare_dir.c difftool/node_compare.c sqfsdiff_SOURCES += difftool/compare_files.c difftool/super.c sqfsdiff_SOURCES += difftool/extract.c difftool/options.c -sqfsdiff_LDADD = libcommon.a libsquashfs.la libutil.la $(LZO_LIBS) +sqfsdiff_LDADD = libcommon.a libsquashfs.la libutil.la $(LZO_LIBS) libfstree.a bin_PROGRAMS += sqfsdiff diff --git a/include/fstree.h b/include/fstree.h index a63c593..44428cd 100644 --- a/include/fstree.h +++ b/include/fstree.h @@ -183,4 +183,13 @@ void tree_node_sort_recursive(tree_node_t *root); */ sqfs_u32 get_source_date_epoch(void); +/* + Convert back to forward slashed, remove all preceeding and trailing slashes, + collapse all sequences of slashes, remove all path components that are '.' + and returns failure state if one of the path components is '..'. + + Returns 0 on success. +*/ +int canonicalize_name(char *filename); + #endif /* FSTREE_H */ diff --git a/include/util/util.h b/include/util/util.h index a133067..7aa4f31 100644 --- a/include/util/util.h +++ b/include/util/util.h @@ -33,13 +33,4 @@ void *alloc_flex(size_t base_size, size_t item_size, size_t nmemb); SQFS_INTERNAL void *alloc_array(size_t item_size, size_t nmemb); -/* - Convert back to forward slashed, remove all preceeding and trailing slashes, - collapse all sequences of slashes, remove all path components that are '.' - and returns failure state if one of the path components is '..'. - - Returns 0 on success. -*/ -SQFS_INTERNAL int canonicalize_name(char *filename); - #endif /* UTIL_H */ diff --git a/lib/fstree/Makemodule.am b/lib/fstree/Makemodule.am index be5f8fc..6638480 100644 --- a/lib/fstree/Makemodule.am +++ b/lib/fstree/Makemodule.am @@ -6,6 +6,7 @@ libfstree_a_SOURCES += lib/fstree/add_by_path.c libfstree_a_SOURCES += include/fstree.h libfstree_a_SOURCES += lib/fstree/gen_file_list.c libfstree_a_SOURCES += lib/fstree/source_date_epoch.c +libfstree_a_SOURCES += lib/fstree/canonicalize_name.c libfstree_a_CFLAGS = $(AM_CFLAGS) libfstree_a_CPPFLAGS = $(AM_CPPFLAGS) diff --git a/lib/fstree/canonicalize_name.c b/lib/fstree/canonicalize_name.c new file mode 100644 index 0000000..f35307f --- /dev/null +++ b/lib/fstree/canonicalize_name.c @@ -0,0 +1,60 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * canonicalize_name.c + * + * Copyright (C) 2019 David Oberhollenzer + */ +#include "config.h" +#include "fstree.h" + +static void normalize_slashes(char *filename) +{ + char *dst = filename, *src = filename; + + while (*src == '/' || *src == '\\') + ++src; + + while (*src != '\0') { + if (*src == '/' || *src == '\\') { + while (*src == '/' || *src == '\\') + ++src; + if (*src == '\0') + break; + *(dst++) = '/'; + } else { + *(dst++) = *(src++); + } + } + + *dst = '\0'; +} + +int canonicalize_name(char *filename) +{ + char *dst = filename, *src = filename; + + normalize_slashes(filename); + + while (*src != '\0') { + if (src[0] == '.') { + if (src[1] == '\0') + break; + if (src[1] == '/') { + src += 2; + continue; + } + if (src[1] == '.' && (src[2] == '/' || src[2] == '\0')) + return -1; + } + + while (*src != '\0' && *src != '/') + *(dst++) = *(src++); + + if (*src == '/') + *(dst++) = *(src++); + } + + *dst = '\0'; + normalize_slashes(filename); + return 0; +} diff --git a/lib/util/Makemodule.am b/lib/util/Makemodule.am index 6a1a6a8..07e94e2 100644 --- a/lib/util/Makemodule.am +++ b/lib/util/Makemodule.am @@ -1,6 +1,5 @@ libutil_la_SOURCES = include/util/util.h include/util/str_table.h -libutil_la_SOURCES += lib/util/str_table.c lib/util/canonicalize_name.c -libutil_la_SOURCES += lib/util/alloc.c +libutil_la_SOURCES += lib/util/str_table.c lib/util/alloc.c libutil_la_CFLAGS = $(AM_CFLAGS) libutil_la_CPPFLAGS = $(AM_CPPFLAGS) libutil_la_LDFLAGS = $(AM_LDFLAGS) diff --git a/lib/util/canonicalize_name.c b/lib/util/canonicalize_name.c deleted file mode 100644 index 33e1c0b..0000000 --- a/lib/util/canonicalize_name.c +++ /dev/null @@ -1,61 +0,0 @@ -/* SPDX-License-Identifier: LGPL-3.0-or-later */ -/* - * canonicalize_name.c - * - * Copyright (C) 2019 David Oberhollenzer - */ -#include "config.h" - -#include "util/util.h" - -static void normalize_slashes(char *filename) -{ - char *dst = filename, *src = filename; - - while (*src == '/' || *src == '\\') - ++src; - - while (*src != '\0') { - if (*src == '/' || *src == '\\') { - while (*src == '/' || *src == '\\') - ++src; - if (*src == '\0') - break; - *(dst++) = '/'; - } else { - *(dst++) = *(src++); - } - } - - *dst = '\0'; -} - -int canonicalize_name(char *filename) -{ - char *dst = filename, *src = filename; - - normalize_slashes(filename); - - while (*src != '\0') { - if (src[0] == '.') { - if (src[1] == '\0') - break; - if (src[1] == '/') { - src += 2; - continue; - } - if (src[1] == '.' && (src[2] == '/' || src[2] == '\0')) - return -1; - } - - while (*src != '\0' && *src != '/') - *(dst++) = *(src++); - - if (*src == '/') - *(dst++) = *(src++); - } - - *dst = '\0'; - normalize_slashes(filename); - return 0; -} diff --git a/tar/Makemodule.am b/tar/Makemodule.am index 4d28bb7..63b309c 100644 --- a/tar/Makemodule.am +++ b/tar/Makemodule.am @@ -1,9 +1,9 @@ sqfs2tar_SOURCES = tar/sqfs2tar.c sqfs2tar_LDADD = libcommon.a libsquashfs.la libtar.a libcompat.a libutil.la -sqfs2tar_LDADD += $(LZO_LIBS) +sqfs2tar_LDADD += libfstree.a $(LZO_LIBS) tar2sqfs_SOURCES = tar/tar2sqfs.c tar2sqfs_LDADD = libcommon.a libsquashfs.la libtar.a -tar2sqfs_LDADD += libfstree.a libcompat.a libutil.la $(LZO_LIBS) +tar2sqfs_LDADD += libfstree.a libcompat.a libutil.la libfstree.a $(LZO_LIBS) bin_PROGRAMS += sqfs2tar tar2sqfs diff --git a/tests/Makemodule.am b/tests/Makemodule.am index 93f286d..007b087 100644 --- a/tests/Makemodule.am +++ b/tests/Makemodule.am @@ -1,5 +1,5 @@ test_canonicalize_name_SOURCES = tests/canonicalize_name.c -test_canonicalize_name_LDADD = libutil.la +test_canonicalize_name_LDADD = libfstree.a test_str_table_SOURCES = tests/str_table.c test_str_table_LDADD = libutil.la libcompat.a diff --git a/tests/canonicalize_name.c b/tests/canonicalize_name.c index cabf716..3601569 100644 --- a/tests/canonicalize_name.c +++ b/tests/canonicalize_name.c @@ -5,8 +5,7 @@ * Copyright (C) 2019 David Oberhollenzer */ #include "config.h" - -#include "util/util.h" +#include "fstree.h" #include #include diff --git a/unpack/Makemodule.am b/unpack/Makemodule.am index 16d7ce1..f2832a3 100644 --- a/unpack/Makemodule.am +++ b/unpack/Makemodule.am @@ -3,6 +3,6 @@ rdsquashfs_SOURCES += unpack/list_files.c unpack/options.c rdsquashfs_SOURCES += unpack/restore_fstree.c unpack/describe.c rdsquashfs_SOURCES += unpack/fill_files.c unpack/dump_xattrs.c rdsquashfs_LDADD = libcommon.a libcompat.a libsquashfs.la libutil.la -rdsquashfs_LDADD += $(LZO_LIBS) +rdsquashfs_LDADD += libfstree.a $(LZO_LIBS) bin_PROGRAMS += rdsquashfs -- cgit v1.2.3