Skip to content

Commit

Permalink
NDMP: Fix handling of different vendors regarding slashes
Browse files Browse the repository at this point in the history
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
  • Loading branch information
pstorz committed Mar 2, 2017
1 parent 01e8411 commit 924ecbe
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/dird/ndmp_fhdb_common.c
Expand Up @@ -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);
Expand All @@ -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, "/");
}
}
Expand Down

0 comments on commit 924ecbe

Please sign in to comment.