Removes need for external stat() code when checking for timechange.
Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org>
Autobuild-Date(master): Fri Jan 27 08:30:35 UTC 2023 on atb-devel-224
const char *fname, const char *subfname)
{
struct file_lists *f = *list;
- struct stat sb = {0};
- int rc;
while (f) {
if (f->name && !strcmp(f->name, fname))
*list = f;
}
- rc = stat(subfname, &sb);
- if (rc != 0) {
- return;
- }
- f->modtime = get_mtimespec(&sb);
-
+ /* If file_modtime() fails it leaves f->modtime as zero. */
+ (void)file_modtime(subfname, &f->modtime);
return;
fail:
{
sbcErr err;
uint64_t new_csn;
+ int rc;
+ struct timespec mt = {0};
if (!file_exist(ctx->path)) {
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) {
return SBC_ERR_OK;
}
struct smbconf_csn *csn,
const char *service, const char *param)
{
+ struct timespec mt = {0};
+
if (csn == NULL) {
return;
}
- csn->csn = (uint64_t)file_modtime(ctx->path);
+ (void)file_modtime(ctx->path, &mt);
+ csn->csn = (uint64_t)mt.tv_sec;
}
/**
_PUBLIC_ bool file_exist(const char *fname);
/**
- Check a files mod time.
-**/
-_PUBLIC_ time_t file_modtime(const char *fname);
+ * @brief Return a files modification time.
+ *
+ * @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 a files mod time.
-**/
-
-_PUBLIC_ time_t file_modtime(const char *fname)
+ * @brief Return a files modification time.
+ *
+ * @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)
{
- struct stat st;
-
- if (stat(fname,&st) != 0)
- return(0);
+ struct stat st = {0};
+
+ if (stat(fname, &st) != 0) {
+ return errno;
+ }
- return(st.st_mtime);
+ *mt = get_mtimespec(&st);
+ return 0;
}
/**