+/* check if a file have changed during backup and display an error */
+bool has_file_changed(JCR *jcr, FF_PKT *ff_pkt)
+{
+ struct stat statp;
+ Dmsg1(500, "has_file_changed fname=%s\n",ff_pkt->fname);
+
+ if (ff_pkt->type != FT_REG) { /* not a regular file */
+ return false;
+ }
+
+ if (lstat(ff_pkt->fname, &statp) != 0) {
+ berrno be;
+ Jmsg(jcr, M_WARNING, 0,
+ _("Cannot stat file %s: ERR=%s\n"),ff_pkt->fname,be.bstrerror());
+ return true;
+ }
+
+ if (statp.st_mtime != ff_pkt->statp.st_mtime) {
+ /* TODO: add time of changes */
+ Jmsg(jcr, M_ERROR, 0, _("%s mtime changed during backup.\n"), ff_pkt->fname);
+ return true;
+ }
+
+ if (statp.st_ctime != ff_pkt->statp.st_ctime) {
+ /* TODO: add time of changes */
+ Jmsg(jcr, M_ERROR, 0, _("%s ctime changed during backup.\n"), ff_pkt->fname);
+ return true;
+ }
+
+ if (statp.st_size != ff_pkt->statp.st_size) {
+ /* TODO: add size change */
+ Jmsg(jcr, M_ERROR, 0, _("%s size changed during backup.\n"),ff_pkt->fname);
+ return true;
+ }
+
+ if ((statp.st_blksize != ff_pkt->statp.st_blksize) ||
+ (statp.st_blocks != ff_pkt->statp.st_blocks)) {
+ /* TODO: add size change */
+ Jmsg(jcr, M_ERROR, 0, _("%s size changed during backup.\n"),ff_pkt->fname);
+ return true;
+ }
+
+ return false;
+}
+
+/*
+ * In incremental/diffential or accurate backup, we
+ * say if the current file has changed.
+ */
+static bool check_changes(JCR *jcr, FF_PKT *ff_pkt)
+{
+ /* in special mode (like accurate backup), user can
+ * choose his comparison function.
+ */
+ if (ff_pkt->check_fct) {
+ return ff_pkt->check_fct(jcr, ff_pkt);
+ }
+
+ /* in normal modes (incr/diff), we use this default
+ * behaviour
+ */
+ if (ff_pkt->incremental &&
+ (ff_pkt->statp.st_mtime < ff_pkt->save_time &&
+ ((ff_pkt->flags & FO_MTIMEONLY) ||
+ ff_pkt->statp.st_ctime < ff_pkt->save_time)))
+ {
+ return false;
+ }
+
+ return true;
+}
+