mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
cat, diff: avoid double slashes in paths (RHBZ#1151910).
In full_path, skip the trailing slash in the base directory when different than "/", as the slash will eventually be added when building the resulting path.
This commit is contained in:
committed by
Richard W.M. Jones
parent
e5befcacc5
commit
87941d183f
@@ -138,13 +138,18 @@ full_path (const char *dir, const char *name)
|
||||
{
|
||||
int r;
|
||||
char *path;
|
||||
int len;
|
||||
|
||||
len = strlen (dir);
|
||||
if (len > 0 && dir[len - 1] == '/')
|
||||
--len;
|
||||
|
||||
if (STREQ (dir, "/"))
|
||||
r = asprintf (&path, "/%s", name ? name : "");
|
||||
else if (name)
|
||||
r = asprintf (&path, "%s/%s", dir, name);
|
||||
r = asprintf (&path, "%.*s/%s", len, dir, name);
|
||||
else
|
||||
r = asprintf (&path, "%s", dir);
|
||||
r = asprintf (&path, "%.*s", len, dir);
|
||||
|
||||
if (r == -1) {
|
||||
perror ("asprintf");
|
||||
|
||||
Reference in New Issue
Block a user