def when_unlink_rmdir(self, changelogfile, data):
        # E <GFID> <UNLINK|RMDIR> <PGFID>/<BASENAME>
        pgfid1, bn1 = data[3].split("/", 1)

        if self.args.no_encode:
            bn1 = unquote_plus_space_newline(bn1).strip()

        deleted_path = data[4] if len(data) == 5 else ""
        if deleted_path != "":
            deleted_path = unquote_plus_space_newline(deleted_path)
            deleted_path = output_path_prepare(deleted_path, self.args)

        if self.gfidpath_exists({
                "gfid": data[1],
                "type": "NEW",
                "pgfid1": pgfid1,
                "bn1": bn1
        }):
            # If path exists in table as NEW with same GFID
            # Delete that row
            self.gfidpath_delete({
                "gfid": data[1],
                "type": "NEW",
                "pgfid1": pgfid1,
                "bn1": bn1
            })
        else:
            # Else Record as DELETE
            self.gfidpath_add(changelogfile,
                              RecordType.DELETE,
                              data[1],
                              pgfid1,
                              bn1,
                              path1=deleted_path)

        # Update path1 as deleted_path if pgfid1 and bn1 is same as deleted
        self.gfidpath_update({"path1": deleted_path}, {
            "gfid": data[1],
            "pgfid1": pgfid1,
            "bn1": bn1
        })

        # Update path2 as deleted_path if pgfid2 and bn2 is same as deleted
        self.gfidpath_update({"path2": deleted_path}, {
            "type": RecordType.RENAME,
            "gfid": data[1],
            "pgfid2": pgfid1,
            "bn2": bn1
        })

        # If deleted directory is parent for somebody
        query1 = """UPDATE gfidpath SET path1 = ? || '{0}' || bn1
        WHERE pgfid1 = ? AND path1 != ''""".format(self.path_sep)
        self.cursor.execute(query1, (deleted_path, data[1]))

        query1 = """UPDATE gfidpath SET path2 = ? || '{0}' || bn1
        WHERE pgfid2 = ? AND path2 != ''""".format(self.path_sep)
        self.cursor.execute(query1, (deleted_path, data[1]))
Exemple #2
0
    def when_link_symlink(self, changelogfile, data):
        # E <GFID> <LINK|SYMLINK> <PGFID>/<BASENAME>
        # Add as New record in Db as Type NEW
        pgfid1, bn1 = data[3].split("/", 1)
        if self.args.no_encode:
            bn1 = unquote_plus_space_newline(bn1).strip()

        self.gfidpath_add(changelogfile, RecordType.NEW, data[1], pgfid1, bn1)
    def when_link_symlink(self, changelogfile, data):
        # E <GFID> <LINK|SYMLINK> <PGFID>/<BASENAME>
        # Add as New record in Db as Type NEW
        pgfid1, bn1 = data[3].split("/", 1)
        if self.args.no_encode:
            bn1 = unquote_plus_space_newline(bn1).strip()

        self.gfidpath_add(changelogfile, RecordType.NEW, data[1], pgfid1, bn1)
    def when_create_mknod_mkdir(self, changelogfile, data):
        # E <GFID> <MKNOD|CREATE|MKDIR> <MODE> <USER> <GRP> <PGFID>/<BNAME>
        # Add the Entry to DB
        pgfid1, bn1 = data[6].split("/", 1)

        if self.args.no_encode:
            bn1 = unquote_plus_space_newline(bn1).strip()

        self.gfidpath_add(changelogfile, RecordType.NEW, data[1], pgfid1, bn1)
Exemple #5
0
    def when_create_mknod_mkdir(self, changelogfile, data):
        # E <GFID> <MKNOD|CREATE|MKDIR> <MODE> <USER> <GRP> <PGFID>/<BNAME>
        # Add the Entry to DB
        pgfid1, bn1 = data[6].split("/", 1)

        if self.args.no_encode:
            bn1 = unquote_plus_space_newline(bn1).strip()

        self.gfidpath_add(changelogfile, RecordType.NEW, data[1], pgfid1, bn1)
Exemple #6
0
    def when_unlink_rmdir(self, changelogfile, data):
        # E <GFID> <UNLINK|RMDIR> <PGFID>/<BASENAME>
        pgfid1, bn1 = data[3].split("/", 1)

        if self.args.no_encode:
            bn1 = unquote_plus_space_newline(bn1).strip()

        deleted_path = data[4] if len(data) == 5 else ""
        if deleted_path != "":
            deleted_path = unquote_plus_space_newline(deleted_path)
            deleted_path = output_path_prepare(deleted_path, self.args)

        if self.gfidpath_exists({"gfid": data[1], "type": "NEW",
                                 "pgfid1": pgfid1, "bn1": bn1}):
            # If path exists in table as NEW with same GFID
            # Delete that row
            self.gfidpath_delete({"gfid": data[1], "type": "NEW",
                                  "pgfid1": pgfid1, "bn1": bn1})
        else:
            # Else Record as DELETE
            self.gfidpath_add(changelogfile, RecordType.DELETE, data[1],
                              pgfid1, bn1, path1=deleted_path)

        # Update path1 as deleted_path if pgfid1 and bn1 is same as deleted
        self.gfidpath_update({"path1": deleted_path}, {"gfid": data[1],
                                                       "pgfid1": pgfid1,
                                                       "bn1": bn1})

        # Update path2 as deleted_path if pgfid2 and bn2 is same as deleted
        self.gfidpath_update({"path2": deleted_path}, {
            "type": RecordType.RENAME,
            "gfid": data[1],
            "pgfid2": pgfid1,
            "bn2": bn1})

        # If deleted directory is parent for somebody
        query1 = """UPDATE gfidpath SET path1 = ? || '{0}' || bn1
        WHERE pgfid1 = ? AND path1 != ''""".format(self.path_sep)
        self.cursor.execute(query1, (deleted_path, data[1]))

        query1 = """UPDATE gfidpath SET path2 = ? || '{0}' || bn1
        WHERE pgfid2 = ? AND path2 != ''""".format(self.path_sep)
        self.cursor.execute(query1, (deleted_path, data[1]))
Exemple #7
0
    def when_rename(self, changelogfile, data):
        # E <GFID> RENAME <OLD_PGFID>/<BNAME> <PGFID>/<BNAME>
        pgfid1, bn1 = data[3].split("/", 1)
        pgfid2, bn2 = data[4].split("/", 1)

        if self.args.no_encode:
            bn1 = unquote_plus_space_newline(bn1).strip()
            bn2 = unquote_plus_space_newline(bn2).strip()

        if self.gfidpath_exists({"gfid": data[1], "type": "NEW",
                                 "pgfid1": pgfid1, "bn1": bn1}):
            # If <OLD_PGFID>/<BNAME> is same as CREATE, Update
            # <NEW_PGFID>/<BNAME> in NEW.
            self.gfidpath_update({"pgfid1": pgfid2, "bn1": bn2},
                                 {"gfid": data[1], "type": "NEW",
                                  "pgfid1": pgfid1, "bn1": bn1})
        elif self.gfidpath_exists({"gfid": data[1], "type": "RENAME",
                                   "pgfid2": pgfid1, "bn2": bn1}):
            # If we are renaming file back to original name then just
            # delete the entry since it will effectively be a no-op
            if self.gfidpath_exists({"gfid": data[1], "type": "RENAME",
                                     "pgfid2": pgfid1, "bn2": bn1,
                                     "pgfid1": pgfid2, "bn1": bn2}):
                self.gfidpath_delete({"gfid": data[1], "type": "RENAME",
                                      "pgfid2": pgfid1, "bn2": bn1})
            else:
                # If <OLD_PGFID>/<BNAME> is same as <PGFID2>/<BN2>
                # (may be previous RENAME)
                # then UPDATE <NEW_PGFID>/<BNAME> as <PGFID2>/<BN2>
                self.gfidpath_update({"pgfid2": pgfid2, "bn2": bn2},
                                     {"gfid": data[1], "type": "RENAME",
                                      "pgfid2": pgfid1, "bn2": bn1})
        else:
            # Else insert as RENAME
            self.gfidpath_add(changelogfile, RecordType.RENAME, data[1],
                              pgfid1, bn1, pgfid2, bn2)

        if self.gfidpath_exists({"gfid": data[1], "type": "MODIFY"}):
            # If MODIFY exists already for that GFID, remove it and insert
            # again so that MODIFY entry comes after RENAME entry
            # Output will have MODIFY <NEWNAME>
            self.gfidpath_delete({"gfid": data[1], "type": "MODIFY"})
            self.gfidpath_add(changelogfile, RecordType.MODIFY, data[1])
    def when_rename(self, changelogfile, data):
        # E <GFID> RENAME <OLD_PGFID>/<BNAME> <PGFID>/<BNAME>
        pgfid1, bn1 = data[3].split("/", 1)
        pgfid2, bn2 = data[4].split("/", 1)

        if self.args.no_encode:
            bn1 = unquote_plus_space_newline(bn1).strip()
            bn2 = unquote_plus_space_newline(bn2).strip()

        if self.gfidpath_exists({
                "gfid": data[1],
                "type": "NEW",
                "pgfid1": pgfid1,
                "bn1": bn1
        }):
            # If <OLD_PGFID>/<BNAME> is same as CREATE, Update
            # <NEW_PGFID>/<BNAME> in NEW.
            self.gfidpath_update({
                "pgfid1": pgfid2,
                "bn1": bn2
            }, {
                "gfid": data[1],
                "type": "NEW",
                "pgfid1": pgfid1,
                "bn1": bn1
            })
        elif self.gfidpath_exists({
                "gfid": data[1],
                "type": "RENAME",
                "pgfid2": pgfid1,
                "bn2": bn1
        }):
            # If we are renaming file back to original name then just
            # delete the entry since it will effectively be a no-op
            if self.gfidpath_exists({
                    "gfid": data[1],
                    "type": "RENAME",
                    "pgfid2": pgfid1,
                    "bn2": bn1,
                    "pgfid1": pgfid2,
                    "bn1": bn2
            }):
                self.gfidpath_delete({
                    "gfid": data[1],
                    "type": "RENAME",
                    "pgfid2": pgfid1,
                    "bn2": bn1
                })
            else:
                # If <OLD_PGFID>/<BNAME> is same as <PGFID2>/<BN2>
                # (may be previous RENAME)
                # then UPDATE <NEW_PGFID>/<BNAME> as <PGFID2>/<BN2>
                self.gfidpath_update({
                    "pgfid2": pgfid2,
                    "bn2": bn2
                }, {
                    "gfid": data[1],
                    "type": "RENAME",
                    "pgfid2": pgfid1,
                    "bn2": bn1
                })
        else:
            # Else insert as RENAME
            self.gfidpath_add(changelogfile, RecordType.RENAME, data[1],
                              pgfid1, bn1, pgfid2, bn2)

        if self.gfidpath_exists({"gfid": data[1], "type": "MODIFY"}):
            # If MODIFY exists already for that GFID, remove it and insert
            # again so that MODIFY entry comes after RENAME entry
            # Output will have MODIFY <NEWNAME>
            self.gfidpath_delete({"gfid": data[1], "type": "MODIFY"})
            self.gfidpath_add(changelogfile, RecordType.MODIFY, data[1])