Changeset 7d8d744 in trunk


Ignore:
Timestamp:
2019-02-26T19:26:37Z (6 years ago)
Author:
Jean-Paul Calderone <exarkun@…>
Branches:
master
Children:
9244956
Parents:
248449f
Message:

Convert Downloader._process

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified src/allmydata/frontends/magic_folder.py

    r248449f r7d8d744  
    813813)
    814814
     815_STATUS = Field.for_types(
     816    u"status",
     817    # Should just be unicode...
     818    [unicode, bytes],
     819    u"The status of an item in a processing queue.",
     820)
     821
     822QUEUED_ITEM_STATUS_CHANGE = MessageType(
     823    u"magic-folder:item:status-change",
     824    [eliotutil.RELPATH, _STATUS],
     825    u"A queued item changed status.",
     826)
     827
     828_CONFLICT_REASON = Field.for_types(
     829    u"conflict_reason",
     830    [unicode, type(None)],
     831    u"A human-readable explanation of why a file was in conflict.",
     832    eliotutil.validateSetMembership({
     833        u"dbentry mismatch metadata",
     834        u"dbentry newer version",
     835        u"last_downloaded_uri mismatch",
     836        u"file appeared",
     837    }),
     838)
     839
     840CHECKING_CONFLICTS = ActionType(
     841    u"magic-folder:item:checking-conflicts",
     842    [],
     843    [_IS_CONFLICT, _CONFLICT_REASON],
     844    u"A potential download item is being checked to determine if it is in a conflicted state.",
     845)
     846
     847REMOTE_DIRECTORY_CREATED = MessageType(
     848    u"magic-folder:remote-directory-created",
     849    [],
     850    u"The downloader found a new directory in the DMD.",
     851)
     852
     853REMOTE_DIRECTORY_DELETED = MessageType(
     854    u"magic-folder:remote-directory-deleted",
     855    [],
     856    u"The downloader found a directory has been deleted from the DMD.",
     857)
     858
    815859class QueueMixin(HookMixin):
    816860    """
     
    10251069            current_time = time.time()
    10261070        self._status_history[status] = current_time
     1071        QUEUED_ITEM_STATUS_CHANGE.log(
     1072            relpath=self.relpath_u,
     1073            status=status,
     1074        )
    10271075
    10281076    def status_time(self, state):
     
    17511799                    self._count("objects_queued")
    17521800                else:
    1753                     self._log("Excluding %r" % (relpath_u,))
    17541801                    self._call_hook(None, 'processed', async=True)  # await this maybe-Deferred??
    17551802
    1756             self._log("deque after = %r" % (self._deque,))
    17571803        d.addCallback(_filter_batch_to_deque)
    17581804        return d.addActionFinish()
     
    18521898            #     uploaded.
    18531899
    1854             if db_entry:
    1855                 # * 2c. If any of the following are true, then classify as a conflict:
    1856                 #   * i. there are pending notifications of changes to ``foo``;
    1857                 #   * ii. the last-seen statinfo is either absent (i.e. there is
    1858                 #     no entry in the database for this path), or different from the
    1859                 #     current statinfo;
    1860 
    1861                 if current_statinfo.exists:
    1862                     self._log("checking conflicts {}".format(item.relpath_u))
    1863                     if (db_entry.mtime_ns != current_statinfo.mtime_ns or \
    1864                         db_entry.ctime_ns != current_statinfo.ctime_ns or \
    1865                         db_entry.size != current_statinfo.size):
     1900            with CHECKING_CONFLICTS() as action:
     1901                if db_entry:
     1902                    # * 2c. If any of the following are true, then classify as a conflict:
     1903                    #   * i. there are pending notifications of changes to ``foo``;
     1904                    #   * ii. the last-seen statinfo is either absent (i.e. there is
     1905                    #     no entry in the database for this path), or different from the
     1906                    #     current statinfo;
     1907
     1908                    if current_statinfo.exists:
     1909                        conflict_reason = None
     1910                        if (db_entry.mtime_ns != current_statinfo.mtime_ns or \
     1911                            db_entry.ctime_ns != current_statinfo.ctime_ns or \
     1912                            db_entry.size != current_statinfo.size):
     1913                            is_conflict = True
     1914                            conflict_reason = u"dbentry mismatch metadata"
     1915
     1916                        if db_entry.last_downloaded_uri is None \
     1917                           or db_entry.last_uploaded_uri is None \
     1918                           or dmd_last_downloaded_uri is None:
     1919                            # we've never downloaded anything before for this
     1920                            # file, but the other side might have created a new
     1921                            # file "at the same time"
     1922                            if db_entry.version >= item.metadata['version']:
     1923                                is_conflict = True
     1924                                conflict_reason = u"dbentry newer version"
     1925                        elif dmd_last_downloaded_uri != db_entry.last_downloaded_uri:
     1926                            is_conflict = True
     1927                            conflict_reason = u"last_downloaded_uri mismatch"
     1928
     1929                else:  # no local db_entry .. but has the file appeared locally meantime?
     1930                    if current_statinfo.exists:
    18661931                        is_conflict = True
    1867                         self._log("conflict because local change0")
    1868 
    1869                     if db_entry.last_downloaded_uri is None \
    1870                        or db_entry.last_uploaded_uri is None \
    1871                        or dmd_last_downloaded_uri is None:
    1872                         # we've never downloaded anything before for this
    1873                         # file, but the other side might have created a new
    1874                         # file "at the same time"
    1875                         if db_entry.version >= item.metadata['version']:
    1876                             self._log("conflict because my version >= remote version")
    1877                             is_conflict = True
    1878                     elif dmd_last_downloaded_uri != db_entry.last_downloaded_uri:
    1879                         is_conflict = True
    1880                         self._log("conflict because dmd_last_downloaded_uri != db_entry.last_downloaded_uri")
    1881 
    1882             else:  # no local db_entry .. but has the file appeared locally meantime?
    1883                 if current_statinfo.exists:
    1884                     is_conflict = True
    1885                     self._log("conflict because local change1")
     1932                        conflict_reason = u"file appeared"
     1933
     1934                action.add_success_fields(
     1935                    is_conflict=is_conflict,
     1936                    conflict_reason=conflict_reason,
     1937                )
    18861938
    18871939            if is_conflict:
     
    18901942            if item.relpath_u.endswith(u"/"):
    18911943                if item.metadata.get('deleted', False):
    1892                     self._log("rmdir(%r) ignored" % (abspath_u,))
     1944                    REMOTE_DIRECTORY_DELETED.log()
    18931945                else:
    1894                     self._log("mkdir(%r)" % (abspath_u,))
     1946                    REMOTE_DIRECTORY_CREATED.log()
    18951947                    d.addCallback(lambda ign: fileutil.make_dirs(abspath_u))
    18961948                    d.addCallback(lambda ign: abspath_u)
     
    19131965        def trap_conflicts(f):
    19141966            f.trap(ConflictError)
    1915             self._log("IGNORE CONFLICT ERROR %r" % f)
    19161967            return False
    19171968        d.addErrback(trap_conflicts)
Note: See TracChangeset for help on using the changeset viewer.