mirror of
https://github.com/samba-team/samba.git
synced 2025-04-24 22:50:23 +03:00
s3:lib: Change file_modtime() to return an error code and a struct timespec.
Removes need for external stat() code when checking for timechange. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15301 Signed-off-by: Jeremy Allison <jra@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org> (cherry picked from commit 7e0eb0f31a24ef6d1742363d70090875d1037dc2) Autobuild-User(v4-18-test): Jule Anger <janger@samba.org> Autobuild-Date(v4-18-test): Fri Feb 10 11:46:16 UTC 2023 on atb-devel-224
This commit is contained in:
parent
9a3fb55870
commit
c714e36950
@ -1009,8 +1009,6 @@ void add_to_file_list(TALLOC_CTX *mem_ctx, struct file_lists **list,
|
|||||||
const char *fname, const char *subfname)
|
const char *fname, const char *subfname)
|
||||||
{
|
{
|
||||||
struct file_lists *f = *list;
|
struct file_lists *f = *list;
|
||||||
struct stat sb = {0};
|
|
||||||
int rc;
|
|
||||||
|
|
||||||
while (f) {
|
while (f) {
|
||||||
if (f->name && !strcmp(f->name, fname))
|
if (f->name && !strcmp(f->name, fname))
|
||||||
@ -1036,12 +1034,8 @@ void add_to_file_list(TALLOC_CTX *mem_ctx, struct file_lists **list,
|
|||||||
*list = f;
|
*list = f;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = stat(subfname, &sb);
|
/* If file_modtime() fails it leaves f->modtime as zero. */
|
||||||
if (rc != 0) {
|
(void)file_modtime(subfname, &f->modtime);
|
||||||
return;
|
|
||||||
}
|
|
||||||
f->modtime = get_mtimespec(&sb);
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
|
@ -184,12 +184,23 @@ static sbcErr smbconf_txt_load_file(struct smbconf_ctx *ctx)
|
|||||||
{
|
{
|
||||||
sbcErr err;
|
sbcErr err;
|
||||||
uint64_t new_csn;
|
uint64_t new_csn;
|
||||||
|
int rc;
|
||||||
|
struct timespec mt = {0};
|
||||||
|
|
||||||
if (!file_exist(ctx->path)) {
|
if (!file_exist(ctx->path)) {
|
||||||
return SBC_ERR_BADFILE;
|
return SBC_ERR_BADFILE;
|
||||||
}
|
}
|
||||||
|
|
||||||
new_csn = (uint64_t)file_modtime(ctx->path);
|
rc = file_modtime(ctx->path, &mt);
|
||||||
|
if (rc != 0) {
|
||||||
|
/*
|
||||||
|
* Not worth mapping errno returned
|
||||||
|
* in rc to SBC_ERR_XXX. Just assume
|
||||||
|
* access denied.
|
||||||
|
*/
|
||||||
|
return SBC_ERR_ACCESS_DENIED;
|
||||||
|
}
|
||||||
|
new_csn = (uint64_t)mt.tv_sec;
|
||||||
if (new_csn == pd(ctx)->csn) {
|
if (new_csn == pd(ctx)->csn) {
|
||||||
return SBC_ERR_OK;
|
return SBC_ERR_OK;
|
||||||
}
|
}
|
||||||
@ -275,11 +286,14 @@ static void smbconf_txt_get_csn(struct smbconf_ctx *ctx,
|
|||||||
struct smbconf_csn *csn,
|
struct smbconf_csn *csn,
|
||||||
const char *service, const char *param)
|
const char *service, const char *param)
|
||||||
{
|
{
|
||||||
|
struct timespec mt = {0};
|
||||||
|
|
||||||
if (csn == NULL) {
|
if (csn == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
csn->csn = (uint64_t)file_modtime(ctx->path);
|
(void)file_modtime(ctx->path, &mt);
|
||||||
|
csn->csn = (uint64_t)mt.tv_sec;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -441,9 +441,15 @@ _PUBLIC_ int create_unlink_tmp(const char *dir);
|
|||||||
_PUBLIC_ bool file_exist(const char *fname);
|
_PUBLIC_ bool file_exist(const char *fname);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Check a files mod time.
|
* @brief Return a files modification time.
|
||||||
**/
|
*
|
||||||
_PUBLIC_ time_t file_modtime(const char *fname);
|
* @param fname The name of the file.
|
||||||
|
*
|
||||||
|
* @param mt A pointer to store the modification time.
|
||||||
|
*
|
||||||
|
* @return 0 on success, errno otherwise.
|
||||||
|
*/
|
||||||
|
_PUBLIC_ int file_modtime(const char *fname, struct timespec *mt);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Check if a directory exists.
|
Check if a directory exists.
|
||||||
|
@ -116,17 +116,24 @@ _PUBLIC_ bool file_exist(const char *fname)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Check a files mod time.
|
* @brief Return a files modification time.
|
||||||
**/
|
*
|
||||||
|
* @param fname The name of the file.
|
||||||
_PUBLIC_ time_t file_modtime(const char *fname)
|
*
|
||||||
|
* @param mt A pointer to store the modification time.
|
||||||
|
*
|
||||||
|
* @return 0 on success, errno otherwise.
|
||||||
|
*/
|
||||||
|
_PUBLIC_ int file_modtime(const char *fname, struct timespec *mt)
|
||||||
{
|
{
|
||||||
struct stat st;
|
struct stat st = {0};
|
||||||
|
|
||||||
if (stat(fname,&st) != 0)
|
|
||||||
return(0);
|
|
||||||
|
|
||||||
return(st.st_mtime);
|
if (stat(fname, &st) != 0) {
|
||||||
|
return errno;
|
||||||
|
}
|
||||||
|
|
||||||
|
*mt = get_mtimespec(&st);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user