add function fc_check_rename_ex
parent
6836337d0a
commit
08f74db732
3
HISTORY
3
HISTORY
|
|
@ -1,11 +1,12 @@
|
|||
|
||||
Version 1.56 2022-02-25
|
||||
Version 1.56 2022-03-09
|
||||
* add function fc_gettid
|
||||
* function normalize_path: NULL from parameter for getcwd
|
||||
* sockopt.[hc] support tcpwritev and tcpreadv
|
||||
* add function fc_iov_get_bytes
|
||||
* rename hash_xxx to fc_hash_xxx
|
||||
* rename trim to fc_trim
|
||||
* add function fc_check_rename_ex
|
||||
|
||||
Version 1.55 2022-01-12
|
||||
* fastcommon php extension adapt to php 8
|
||||
|
|
|
|||
4
make.sh
4
make.sh
|
|
@ -203,12 +203,12 @@ done
|
|||
|
||||
if [ -n "$pthread_path" ]; then
|
||||
LIBS="$LIBS -lpthread"
|
||||
line=$(nm $pthread_path | fgrep pthread_rwlockattr_setkind_np | fgrep -w T)
|
||||
line=$(nm $pthread_path 2>/dev/null | fgrep pthread_rwlockattr_setkind_np | fgrep -w T)
|
||||
if [ -n "$line" ]; then
|
||||
CFLAGS="$CFLAGS -DWITH_PTHREAD_RWLOCKATTR_SETKIND_NP=1"
|
||||
fi
|
||||
elif [ -f /usr/lib/libc_r.so ]; then
|
||||
line=$(nm -D /usr/lib/libc_r.so | grep pthread_create | grep -w T)
|
||||
line=$(nm -D /usr/lib/libc_r.so 2>/dev/null | grep pthread_create | grep -w T)
|
||||
if [ -n "$line" ]; then
|
||||
LIBS="$LIBS -lc_r"
|
||||
fi
|
||||
|
|
|
|||
|
|
@ -1369,10 +1369,10 @@ int safeWriteToFile(const char *filename, const char *buff, \
|
|||
if (rename(tmpFilename, filename) != 0)
|
||||
{
|
||||
result = errno != 0 ? errno : EIO;
|
||||
logError("file: "__FILE__", line: %d, " \
|
||||
"rename file \"%s\" to \"%s\" fail, " \
|
||||
"errno: %d, error info: %s", \
|
||||
__LINE__, tmpFilename, filename, \
|
||||
logError("file: "__FILE__", line: %d, "
|
||||
"rename file \"%s\" to \"%s\" fail, "
|
||||
"errno: %d, error info: %s",
|
||||
__LINE__, tmpFilename, filename,
|
||||
result, STRERROR(result));
|
||||
return result;
|
||||
}
|
||||
|
|
@ -3446,6 +3446,52 @@ int fc_mkdirs_ex(const char *path, const mode_t mode, int *create_count)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int fc_check_rename_ex(const char *oldpath, const char *newpath,
|
||||
const bool overwritten)
|
||||
{
|
||||
int result;
|
||||
|
||||
if (access(oldpath, F_OK) != 0) {
|
||||
result = errno != 0 ? errno : EPERM;
|
||||
if (result != ENOENT) {
|
||||
logError("file: "__FILE__", line: %d, "
|
||||
"access %s fail, errno: %d, error info: %s",
|
||||
__LINE__, oldpath, result, STRERROR(result));
|
||||
return result;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!overwritten) {
|
||||
if (access(newpath, F_OK) == 0) {
|
||||
logError("file: "__FILE__", line: %d, "
|
||||
"dest path: %s already exist",
|
||||
__LINE__, newpath);
|
||||
return EEXIST;
|
||||
} else {
|
||||
result = errno != 0 ? errno : EPERM;
|
||||
if (result != ENOENT) {
|
||||
logError("file: "__FILE__", line: %d, "
|
||||
"access %s fail, errno: %d, error info: %s",
|
||||
__LINE__, newpath, result, STRERROR(result));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (rename(oldpath, newpath) != 0) {
|
||||
result = errno != 0 ? errno : EIO;
|
||||
logError("file: "__FILE__", line: %d, "
|
||||
"rename file \"%s\" to \"%s\" fail, "
|
||||
"errno: %d, error info: %s",
|
||||
__LINE__, oldpath, newpath,
|
||||
result, STRERROR(result));
|
||||
return result;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int fc_get_first_line(const char *filename, char *buff,
|
||||
const int buff_size, string_t *line)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1089,6 +1089,15 @@ static inline int fc_mkdirs(const char *path, const mode_t mode)
|
|||
return fc_mkdirs_ex(path, mode, &create_count);
|
||||
}
|
||||
|
||||
int fc_check_rename_ex(const char *oldpath, const char *newpath,
|
||||
const bool overwritten);
|
||||
|
||||
static inline int fc_check_rename(const char *oldpath, const char *newpath)
|
||||
{
|
||||
const bool overwritten = true;
|
||||
return fc_check_rename_ex(oldpath, newpath, overwritten);
|
||||
}
|
||||
|
||||
int fc_get_first_line(const char *filename, char *buff,
|
||||
const int buff_size, string_t *line);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue