-+ fdbr.FileId = 0;
-+ /* If file_index==0, file is not saved by fd, check them */
-+ if (!db_accurate_get_file_attributes_record(jcr, jcr->db, jcr->fname, backupid, &fdbr)) {
-+ Jmsg(jcr, M_INFO, 0, _("New file: %s\n"), jcr->fname);
-+ Dmsg1(1, _("File not in catalog: %s\n"), jcr->fname);
-+ continue;
-+ } else {
-+ Dmsg1(1, _("File in catalog: %s\n"), jcr->fname);
-+ /*
-+ * mark file record as visited by stuffing the
-+ * current JobId, which is unique, into the MarkId field.
-+ */
-+ db_mark_file_record(jcr, jcr->db, fdbr.FileId, jcr->JobId);
-+ }
-+
-+ Dmsg3(400, "Found %s in catalog. inx=%d Opts=%s\n", jcr->fname,
-+ file_index, Opts_Digest);
-+ decode_stat(fdbr.LStat, &statc, &LinkFIc); /* decode catalog stat */
-+
-+ // TODO: for each JS_Differences, send it to FD for backup
-+ /*
-+ * Loop over options supplied by user and verify the
-+ * fields he requests.
-+ */
-+ stat = JS_Terminated; /* TODO: track changes */
-+ for (p=Opts_Digest; *p; p++) {
-+ char ed1[30], ed2[30];
-+ switch (*p) {
-+ case 'i': /* compare INODEs */
-+ if (statc.st_ino != statf.st_ino) {
-+ Jmsg(jcr, M_INFO, 0, _(" st_ino differ. Cat: %s File: %s\n"),
-+ edit_uint64((uint64_t)statc.st_ino, ed1),
-+ edit_uint64((uint64_t)statf.st_ino, ed2));
-+ stat = JS_Differences;
-+ }
-+ break;
-+ case 'p': /* permissions bits */
-+ if (statc.st_mode != statf.st_mode) {
-+ Jmsg(jcr, M_INFO, 0, _(" st_mode differ. Cat: %x File: %x\n"),
-+ (uint32_t)statc.st_mode, (uint32_t)statf.st_mode);
-+ stat = JS_Differences;
-+ }
-+ break;
-+ case 'n': /* number of links */
-+ if (statc.st_nlink != statf.st_nlink) {
-+ Jmsg(jcr, M_INFO, 0, _(" st_nlink differ. Cat: %d File: %d\n"),
-+ (uint32_t)statc.st_nlink, (uint32_t)statf.st_nlink);
-+ stat = JS_Differences;
-+ }
-+ break;
-+ case 'u': /* user id */
-+ if (statc.st_uid != statf.st_uid) {
-+ Jmsg(jcr, M_INFO, 0, _(" st_uid differ. Cat: %u File: %u\n"),
-+ (uint32_t)statc.st_uid, (uint32_t)statf.st_uid);
-+ stat = JS_Differences;
-+ }
-+ break;
-+ case 'g': /* group id */
-+ if (statc.st_gid != statf.st_gid) {
-+ Jmsg(jcr, M_INFO, 0, _(" st_gid differ. Cat: %u File: %u\n"),
-+ (uint32_t)statc.st_gid, (uint32_t)statf.st_gid);
-+ stat = JS_Differences;
-+ }
-+ break;
-+ case 's': /* size */
-+ if (statc.st_size != statf.st_size) {
-+ Jmsg(jcr, M_INFO, 0, _(" st_size differ. Cat: %s File: %s\n"),
-+ edit_uint64((uint64_t)statc.st_size, ed1),
-+ edit_uint64((uint64_t)statf.st_size, ed2));
-+ stat = JS_Differences;
-+ }
-+ break;
-+ case 'a': /* access time */
-+ if (statc.st_atime != statf.st_atime) {
-+ Jmsg(jcr, M_INFO, 0, _(" st_atime differs\n"));
-+ stat = JS_Differences;
-+ }
-+ break;
-+ case 'm':
-+ if (statc.st_mtime != statf.st_mtime) {
-+ Jmsg(jcr, M_INFO, 0, _(" st_mtime differs\n"));
-+ stat = JS_Differences;
-+ }
-+ break;
-+ case 'c': /* ctime */
-+ if (statc.st_ctime != statf.st_ctime) {
-+ Jmsg(jcr, M_INFO, 0, _(" st_ctime differs\n"));
-+ stat = JS_Differences;
-+ }
-+ break;
-+ case 'd': /* file size decrease */
-+ if (statc.st_size > statf.st_size) {
-+ Jmsg(jcr, M_INFO, 0, _(" st_size decrease. Cat: %s File: %s\n"),
-+ edit_uint64((uint64_t)statc.st_size, ed1),
-+ edit_uint64((uint64_t)statf.st_size, ed2));
-+ stat = JS_Differences;
-+ }
-+ break;
-+ case '5': /* compare MD5 */
-+ Dmsg1(500, "set Do_MD5 for %s\n", jcr->fname);
-+ do_Digest = CRYPTO_DIGEST_MD5;
-+ break;
-+ case '1': /* compare SHA1 */
-+ do_Digest = CRYPTO_DIGEST_SHA1;
-+ break;
-+ case ':':
-+ case 'V':
-+ default:
-+ break;
-+ }
-+ }
-+ if (stat == JS_Differences) {
-+ Jmsg(jcr, M_INFO, 0, _(" fname=%s\n"), jcr->fname);
++
++ if (db_accurate_get_file_attributes_record(jcr, jcr->db, jcr->fname,
++ backupid, &fdbr))
++ {
++ Dmsg2(1, "get_file ok fname=%s fileid=%i\n", jcr->fname, fdbr.FileId);
++
++ if (file_index != 0) {
++ changed = accurate_check_file(jcr, &fdbr, attr, Opts_Digest, &do_Digest);
++ Dmsg1(1, "check_file changed=%i\n", changed);
++
++ if (changed == true) {
++ db_accurate_mark_file_for_backup(jcr, jcr->db, jcr->fname, jcr->JobId);
++ db_accurate_delete_file_record(jcr, jcr->db, fdbr.FileId,
++ backupid);
++ }
++ }
++
++ if (file_index == 0 || changed == false) {
++ Dmsg1(1, "mark_file fileid=%i\n", fdbr.FileId);
++ db_accurate_mark_file_record(jcr, jcr->db, backupid,
++ fdbr.FileId, jcr->JobId);
++ }
++
++ } else if (file_index == 0) {
++ Dmsg1(1, "mark_for_backup fname=%s\n", jcr->fname);
++ db_accurate_mark_file_for_backup(jcr, jcr->db, jcr->fname, jcr->JobId);