Canonicalize dirname(3) behavior.
This commit is contained in:
parent
2a953aed38
commit
ac20ce1924
@ -342,9 +342,11 @@ tarExtractRegularFile(TarInfo *header, int extractFlag, int tostdoutFlag)
|
|||||||
if (extractFlag==TRUE && tostdoutFlag==FALSE) {
|
if (extractFlag==TRUE && tostdoutFlag==FALSE) {
|
||||||
/* Create the path to the file, just in case it isn't there...
|
/* Create the path to the file, just in case it isn't there...
|
||||||
* This should not screw up path permissions or anything. */
|
* This should not screw up path permissions or anything. */
|
||||||
char *dir = dirname (header->name);
|
char *buf, *dir;
|
||||||
|
buf = xstrdup (header->name);
|
||||||
|
dir = dirname (buf);
|
||||||
make_directory (dir, -1, FILEUTILS_RECUR);
|
make_directory (dir, -1, FILEUTILS_RECUR);
|
||||||
free (dir);
|
free (buf);
|
||||||
if ((outFd=open(header->name, O_CREAT|O_TRUNC|O_WRONLY,
|
if ((outFd=open(header->name, O_CREAT|O_TRUNC|O_WRONLY,
|
||||||
header->mode & ~S_IFMT)) < 0) {
|
header->mode & ~S_IFMT)) < 0) {
|
||||||
error_msg(io_error, header->name, strerror(errno));
|
error_msg(io_error, header->name, strerror(errno));
|
||||||
|
@ -22,7 +22,8 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "libbb.h"
|
#include "libbb.h"
|
||||||
|
|
||||||
/* Return a string on the heap containing the directory component of PATH. */
|
/* Return a string containing the path name of the parent
|
||||||
|
* directory of PATH. */
|
||||||
|
|
||||||
char *dirname(const char *path)
|
char *dirname(const char *path)
|
||||||
{
|
{
|
||||||
@ -43,7 +44,8 @@ char *dirname(const char *path)
|
|||||||
s--;
|
s--;
|
||||||
|
|
||||||
if (s < path)
|
if (s < path)
|
||||||
return xstrdup (".");
|
return ".";
|
||||||
else
|
|
||||||
return xstrndup (path, s - path + 1);
|
s[1] = '\0';
|
||||||
|
return path;
|
||||||
}
|
}
|
||||||
|
@ -50,13 +50,17 @@ int make_directory (char *path, long mode, int flags)
|
|||||||
|
|
||||||
if (stat (path, &st) < 0 && errno == ENOENT) {
|
if (stat (path, &st) < 0 && errno == ENOENT) {
|
||||||
int status;
|
int status;
|
||||||
char *parent = dirname (path);
|
char *buf, *parent;
|
||||||
mode_t mask = umask (0);
|
mode_t mask;
|
||||||
|
|
||||||
|
mask = umask (0);
|
||||||
umask (mask);
|
umask (mask);
|
||||||
|
|
||||||
|
buf = xstrdup (path);
|
||||||
|
parent = dirname (buf);
|
||||||
status = make_directory (parent, (0777 & ~mask) | 0300,
|
status = make_directory (parent, (0777 & ~mask) | 0300,
|
||||||
FILEUTILS_RECUR);
|
FILEUTILS_RECUR);
|
||||||
free (parent);
|
free (buf);
|
||||||
|
|
||||||
if (status < 0 || make_directory (path, mode, 0) < 0)
|
if (status < 0 || make_directory (path, mode, 0) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -127,13 +127,15 @@ char *extract_archive(FILE *src_stream, FILE *out_stream, const file_header_t *f
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (function & extract_create_leading_dirs) { /* Create leading directories with default umask */
|
if (function & extract_create_leading_dirs) { /* Create leading directories with default umask */
|
||||||
char *parent = dirname(full_name);
|
char *buf, *parent;
|
||||||
|
buf = xstrdup(full_name);
|
||||||
|
parent = dirname(full_name);
|
||||||
if (make_directory (parent, -1, FILEUTILS_RECUR) != 0) {
|
if (make_directory (parent, -1, FILEUTILS_RECUR) != 0) {
|
||||||
if ((function & extract_quiet) != extract_quiet) {
|
if ((function & extract_quiet) != extract_quiet) {
|
||||||
error_msg("couldn't create leading directories");
|
error_msg("couldn't create leading directories");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
free (parent);
|
free (buf);
|
||||||
}
|
}
|
||||||
switch(file_entry->mode & S_IFMT) {
|
switch(file_entry->mode & S_IFMT) {
|
||||||
case S_IFREG:
|
case S_IFREG:
|
||||||
|
6
tar.c
6
tar.c
@ -342,9 +342,11 @@ tarExtractRegularFile(TarInfo *header, int extractFlag, int tostdoutFlag)
|
|||||||
if (extractFlag==TRUE && tostdoutFlag==FALSE) {
|
if (extractFlag==TRUE && tostdoutFlag==FALSE) {
|
||||||
/* Create the path to the file, just in case it isn't there...
|
/* Create the path to the file, just in case it isn't there...
|
||||||
* This should not screw up path permissions or anything. */
|
* This should not screw up path permissions or anything. */
|
||||||
char *dir = dirname (header->name);
|
char *buf, *dir;
|
||||||
|
buf = xstrdup (header->name);
|
||||||
|
dir = dirname (buf);
|
||||||
make_directory (dir, -1, FILEUTILS_RECUR);
|
make_directory (dir, -1, FILEUTILS_RECUR);
|
||||||
free (dir);
|
free (buf);
|
||||||
if ((outFd=open(header->name, O_CREAT|O_TRUNC|O_WRONLY,
|
if ((outFd=open(header->name, O_CREAT|O_TRUNC|O_WRONLY,
|
||||||
header->mode & ~S_IFMT)) < 0) {
|
header->mode & ~S_IFMT)) < 0) {
|
||||||
error_msg(io_error, header->name, strerror(errno));
|
error_msg(io_error, header->name, strerror(errno));
|
||||||
|
Loading…
Reference in New Issue
Block a user