From 924ecbefcdcec749174e20ffa96cabd15533f36d Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Thu, 2 Mar 2017 13:42:59 +0100 Subject: [PATCH] NDMP: Fix handling of different vendors regarding slashes Different NDMP vendors send the FileHistory Information in different ways, either with or without trailing or leading slash on the filesystem or the filename side. This commit fixes the problems with double or no slashes we had before --- src/dird/ndmp_fhdb_common.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/dird/ndmp_fhdb_common.c b/src/dird/ndmp_fhdb_common.c index 1ad606fc4b5..8c48ab51eca 100644 --- a/src/dird/ndmp_fhdb_common.c +++ b/src/dird/ndmp_fhdb_common.c @@ -64,19 +64,22 @@ extern "C" int bndmp_fhdb_add_file(struct ndmlog *ixlog, int tagc, char *raw_nam } else { ndmp_convert_fstat(fstat, nis->FileIndex, &FileType, attribs); - pm_strcpy(pathname, nis->filesystem); + bool filesystem_ends_with_slash = (nis->filesystem[strlen(nis->filesystem) - 1] == '/'); + bool raw_name_starts_with_slash = (*raw_name == '/'); + bool raw_name_ends_with_slash = (raw_name[strlen(raw_name) - 1] == '/') ; + pm_strcpy(pathname, nis->filesystem); /* * make sure we have a trailing slash */ - if ( pathname.c_str()[strlen(pathname.c_str()) - 1] != '/' ) { + if (!filesystem_ends_with_slash) { pm_strcat(pathname, "/"); } /* * skip leading slash to avoid double slashes */ - if (raw_name == (char*)'/') { + if (raw_name_starts_with_slash) { pm_strcat(pathname, raw_name + 1); } else { pm_strcat(pathname, raw_name); @@ -87,7 +90,7 @@ extern "C" int bndmp_fhdb_add_file(struct ndmlog *ixlog, int tagc, char *raw_nam * A directory needs to end with a '/' * so append it if it is missing */ - if ( pathname.c_str()[strlen(pathname.c_str()) - 1] != '/' ) { + if (!raw_name_ends_with_slash) { pm_strcat(pathname, "/"); } }