diff options
| author | Jeffrey Armstrong <jeffrey.armstrong@approximatrix.com> | 2014-01-05 16:28:21 -0500 |
|---|---|---|
| committer | Jeffrey Armstrong <jeffrey.armstrong@approximatrix.com> | 2014-01-05 16:28:21 -0500 |
| commit | 59a9b205dfb6d68545e75f28083cf68eb064547d (patch) | |
| tree | 1be3a06d55d87d9c93cb3d9660e6eb4e1a16bf5c /db.c | |
| parent | 50ff0e53d94c60860e768100f549e4dfe9110096 (diff) | |
| download | prism-59a9b205dfb6d68545e75f28083cf68eb064547d.tar.gz prism-59a9b205dfb6d68545e75f28083cf68eb064547d.zip | |
Prism can now revert current changes
Diffstat (limited to 'db.c')
| -rw-r--r-- | db.c | 54 |
1 files changed, 50 insertions, 4 deletions
@@ -208,8 +208,6 @@ int res; reader = strchr(reader, ' ') + 1; /* Advance to hash */
reader = strchr(reader, ' ') + 1; /* Advance to filename */
- printf("%s <=> %s\n", filename, reader);
-
#if defined(MSDOS) || defined(WIN32)
res = strcmpi(filename, reader);
#else
@@ -224,8 +222,6 @@ int res; memset(info->hash, 0, 33);
memcpy(info->hash, reader, 32);
- printf("%s\n", info->hash);
-
break;
}
}
@@ -417,3 +413,53 @@ char newhash[33]; return PRET_OK;
}
+
+static int determine_revision(struct db_file *info, int desired_revision)
+{
+char *fname;
+int fnamelength;
+struct stat fileres;
+int res, i;
+
+ if(desired_revision > info->revision)
+ return info->revision;
+
+ fnamelength = strlen(PDB_DIR) + strlen(DIR_SEP) + 32;
+ fname = (char *)malloc(fnamelength*sizeof(char));
+ if(fname == NULL)
+ return PRET_ERROR;
+
+ i = desired_revision+1;
+ do {
+ i--;
+ snprintf(fname, fnamelength, "%s%s%x.%x", PDB_DIR, DIR_SEP, info->id, i);
+ res = stat(fname, &fileres);
+ } while(res != 0 && i > 0);
+
+ if(res == 0)
+ return i;
+
+ return PRET_NOTTRACKED;
+}
+
+int revert(const char *filename, int revision)
+{
+int target_revision;
+struct db_file info;
+int res;
+
+
+ res = get_db_fileinfo(filename, &info);
+ if(res != PRET_OK)
+ return res;
+
+ if(revision < 0)
+ target_revision = info.revision;
+ else {
+ target_revision = determine_revision(&info, revision);
+ if(target_revision < 0)
+ return PRET_NOREVISION;
+ }
+
+ return decompress_file(filename, info.id, target_revision);
+}
|
