Example #1
0
    def _GetLatestYearFromFileEntry(self):
        """Retrieves the maximum (highest value) year from the file entry.

    This function uses the modification time if available otherwise the change
    time (metadata last modification time) is used.

    Returns:
      int: year of the file entry or None.
    """
        file_entry = self.GetFileEntry()
        if not file_entry:
            return

        stat_object = file_entry.GetStat()

        posix_time = getattr(stat_object, 'mtime', None)
        if posix_time is None:
            posix_time = getattr(stat_object, 'ctime', None)

        if posix_time is None:
            logging.warning(
                'Unable to determine modification year from file stat information.'
            )
            return

        try:
            year = timelib.GetYearFromPosixTime(
                posix_time, timezone=self._knowledge_base.timezone)
            return year
        except ValueError as exception:
            logging.error(('Unable to determine creation year from file stat '
                           'information with error: {0!s}').format(exception))
            return
Example #2
0
    def _GetEarliestYearFromFileEntry(self):
        """Retrieves the year from the file entry date and time values.

    This function uses the creation time if available otherwise the change
    time (metadata last modification time) is used.

    Returns:
      An integer containing the year of the file entry or None.
    """
        file_entry = self.GetFileEntry()
        stat_object = file_entry.GetStat()

        posix_time = getattr(stat_object, u'crtime', None)
        if posix_time is None:
            posix_time = getattr(stat_object, u'ctime', None)

        if posix_time is None:
            logging.warning(
                u'Unable to determine creation year from file stat information.'
            )
            return

        try:
            year = timelib.GetYearFromPosixTime(
                posix_time, timezone=self._knowledge_base.timezone)
            return year
        except ValueError as exception:
            logging.error((
                u'Unable to determine creation year from file stat information with '
                u'error: {0:s}').format(exception))
            return
Example #3
0
    def _GetEarliestYearFromFileEntry(self):
        """Retrieves the year from the file entry date and time values.

    This function uses the creation time if available otherwise the change
    time (metadata last modification time) is used.

    Returns:
      int: year of the file entry or None.
    """
        file_entry = self.GetFileEntry()
        if not file_entry:
            return

        # Gzip files don't store the creation or metadata modification times,
        # but the parent file times are relevant.
        if file_entry.TYPE_INDICATOR == dfvfs_definitions.TYPE_INDICATOR_GZIP:
            file_entry = file_entry.GetParentFileEntry()

        stat_object = file_entry.GetStat()

        posix_time = getattr(stat_object, 'crtime', None)
        if posix_time is None:
            posix_time = getattr(stat_object, 'ctime', None)

        if posix_time is None:
            logging.warning(
                'Unable to determine earliest year from file stat information.'
            )
            return

        try:
            year = timelib.GetYearFromPosixTime(
                posix_time, timezone=self._knowledge_base.timezone)
            return year
        except ValueError as exception:
            logging.error((
                'Unable to determine earliest year from file stat information with '
                'error: {0:s}').format(exception))
            return