Compare commits
No commits in common. "a0654b83c0c90a9952bfc1100ecae3076523e60f" and "13fc6964324cda1500f634a1c1ec76f6c45177e6" have entirely different histories.
a0654b83c0
...
13fc696432
3
HISTORY
3
HISTORY
|
|
@ -1,7 +1,4 @@
|
||||||
|
|
||||||
Version 1.77 2025-02-03
|
|
||||||
* impl. shorten_path for /./ and /../
|
|
||||||
|
|
||||||
Version 1.76 2025-01-27
|
Version 1.76 2025-01-27
|
||||||
* get_mounted_filesystems act as program df
|
* get_mounted_filesystems act as program df
|
||||||
* add function get_statfs_by_path
|
* add function get_statfs_by_path
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
%define CommitVersion %(echo $COMMIT_VERSION)
|
%define CommitVersion %(echo $COMMIT_VERSION)
|
||||||
|
|
||||||
Name: libfastcommon
|
Name: libfastcommon
|
||||||
Version: 1.0.76
|
Version: 1.0.75
|
||||||
Release: 1%{?dist}
|
Release: 1%{?dist}
|
||||||
Summary: c common functions library extracted from my open source projects FastDFS
|
Summary: c common functions library extracted from my open source projects FastDFS
|
||||||
License: LGPL
|
License: LGPL
|
||||||
|
|
|
||||||
|
|
@ -3413,77 +3413,6 @@ char *format_http_date(time_t t, BufferInfo *buffer)
|
||||||
return buffer->buff;
|
return buffer->buff;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int shorten_path(char *filepath, const int len)
|
|
||||||
{
|
|
||||||
char src_path[PATH_MAX];
|
|
||||||
char *up_path;
|
|
||||||
char *src;
|
|
||||||
char *dest;
|
|
||||||
char *end;
|
|
||||||
|
|
||||||
if (strstr(filepath, "//") == NULL &&
|
|
||||||
strstr(filepath, "/.") == NULL &&
|
|
||||||
strstr(filepath, "/..") == NULL)
|
|
||||||
{
|
|
||||||
return len;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (len > sizeof(src_path)) {
|
|
||||||
logWarning("file: "__FILE__", line: %d, "
|
|
||||||
"filename length: %d exceeds PATH_MAX: %d",
|
|
||||||
__LINE__, len, (int)sizeof(src_path));
|
|
||||||
return len;
|
|
||||||
}
|
|
||||||
|
|
||||||
memcpy(src_path, filepath, len + 1);
|
|
||||||
end = src_path + len;
|
|
||||||
src = src_path;
|
|
||||||
dest = filepath;
|
|
||||||
while (src < end) {
|
|
||||||
while (src < end && *src != '/') {
|
|
||||||
*dest++ = *src++;
|
|
||||||
}
|
|
||||||
if (src == end) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
//skip continuous slashes
|
|
||||||
do {
|
|
||||||
++src;
|
|
||||||
} while (src < end && *src == '/');
|
|
||||||
|
|
||||||
*dest++ = '/'; //keep the slash
|
|
||||||
while (src < end && *src == '.') {
|
|
||||||
if (*(src + 1) == '/' || *(src + 1) == '\0') {
|
|
||||||
/* ignore subdir "./" */
|
|
||||||
src += 2;
|
|
||||||
} else if ((*(src + 1) == '.') && (*(src + 2) == '/' ||
|
|
||||||
*(src + 2) == '\0'))
|
|
||||||
{
|
|
||||||
/* up one level for subdir "../" */
|
|
||||||
if (dest - filepath > 1) {
|
|
||||||
up_path = (char *)fc_memrchr(filepath,
|
|
||||||
'/', dest - filepath - 1);
|
|
||||||
if (up_path != NULL) {
|
|
||||||
dest = up_path + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
src += 3;
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
//skip continuous slashes
|
|
||||||
while (src < end && *src == '/') {
|
|
||||||
++src;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
*dest = '\0';
|
|
||||||
return dest - filepath;
|
|
||||||
}
|
|
||||||
|
|
||||||
int normalize_path(const string_t *from, const string_t *filename,
|
int normalize_path(const string_t *from, const string_t *filename,
|
||||||
char *full_filename, const int size)
|
char *full_filename, const int size)
|
||||||
{
|
{
|
||||||
|
|
@ -3495,7 +3424,6 @@ int normalize_path(const string_t *from, const string_t *filename,
|
||||||
string_t true_filename;
|
string_t true_filename;
|
||||||
int up_count;
|
int up_count;
|
||||||
int path_len;
|
int path_len;
|
||||||
int len;
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (IS_FILE_RESOURCE_EX(filename)) {
|
if (IS_FILE_RESOURCE_EX(filename)) {
|
||||||
|
|
@ -3505,9 +3433,8 @@ int normalize_path(const string_t *from, const string_t *filename,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*filename->str == '/') {
|
if (*filename->str == '/') {
|
||||||
len = snprintf(full_filename, size, "%.*s",
|
return snprintf(full_filename, size, "%.*s",
|
||||||
filename->len, filename->str);
|
filename->len, filename->str);
|
||||||
return shorten_path(full_filename, len);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (from == NULL) {
|
if (from == NULL) {
|
||||||
|
|
@ -3570,16 +3497,14 @@ int normalize_path(const string_t *from, const string_t *filename,
|
||||||
}
|
}
|
||||||
path_len = last - from->str;
|
path_len = last - from->str;
|
||||||
}
|
}
|
||||||
len = snprintf(full_filename, size, "%.*s/%.*s",
|
return snprintf(full_filename, size, "%.*s/%.*s",
|
||||||
path_len, from->str, (int)(end - start), start);
|
path_len, from->str, (int)(end - start), start);
|
||||||
return shorten_path(full_filename, len);
|
|
||||||
} else {
|
} else {
|
||||||
logWarning("file: "__FILE__", line: %d, "
|
logWarning("file: "__FILE__", line: %d, "
|
||||||
"no \"/\" in the from filename: %.*s",
|
"no \"/\" in the from filename: %.*s",
|
||||||
__LINE__, from->len, from->str);
|
__LINE__, from->len, from->str);
|
||||||
len = snprintf(full_filename, size, "%.*s",
|
return snprintf(full_filename, size, "%.*s",
|
||||||
filename->len, filename->str);
|
filename->len, filename->str);
|
||||||
return shorten_path(full_filename, len);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue