@@ -131,19 +131,29 @@ class BaseMirrorService:
131131 def _queues (self ) -> Queues :
132132 return Queues ()
133133
134+ @classmethod
135+ def may_mirror (cls , catalog : CatalogName , file_size : int = 0 ) -> bool :
136+ """
137+ Test whether it makes sense to request the mirroring of files from the
138+ given catalog if they are of the given size or larger. If this method
139+ returns True, such files may or may not be mirrored. If this method
140+ returns False, the service will definitely refuse to mirror such files,
141+ although it may accept smaller files.
142+ """
143+ if config .enable_mirroring :
144+ max_size = config .catalogs [catalog ].mirror_limit
145+ return max_size is None or file_size <= max_size
146+ else :
147+ return False
148+
134149 def mirror_sources (self ,
135150 catalog : CatalogName ,
136151 sources : Iterable [tuple [SourceRef , SourceConfig ]]
137152 ):
138- mirror_limit = config .catalogs [catalog ].mirror_limit
139- if mirror_limit is not None and mirror_limit < 0 :
140- log .info ('Not mirroring any files in catalog %r because the file '
141- 'size limit is negative' , catalog )
142- else :
143-
153+ if self .may_mirror (catalog ):
144154 def messages ():
145- for source , cfg in sources :
146- if cfg .mirror :
155+ for source , source_config in sources :
156+ if source_config .mirror :
147157 log .info ('Mirroring files in source %r from catalog %r' ,
148158 str (source .spec ), catalog )
149159 yield MirrorSourceAction (catalog = catalog , source = source )
@@ -153,6 +163,9 @@ def messages():
153163 str (source .spec ), catalog )
154164
155165 self ._queue_messages (messages ())
166+ else :
167+ log .info ('Not mirroring any files in catalog %r because the file '
168+ 'size limit is negative' , catalog )
156169
157170 def mirror_file (self , catalog : CatalogName , source : SourceRef , file : File ):
158171 self ._queue_messages ([MirrorFileAction (catalog = catalog ,
@@ -238,17 +251,16 @@ def _list_public_source_ids(self, catalog: CatalogName) -> set[str]:
238251 def _ (self , a : MirrorPartitionAction ) -> Iterable [MirrorAction ]:
239252 plugin = self ._repository_plugin (a .catalog )
240253 files = plugin .list_files (a .source , a .prefix )
241- max_size = config .catalogs [a .catalog ].mirror_limit
242254 for file in files :
243255 assert file .size is not None , R ('File size unknown' , file )
244- if max_size is not None and file .size > max_size :
245- log .info ('Not mirroring file to save cost: %r' , file )
246- else :
256+ if self .may_mirror (a .catalog , file .size ):
247257 log .debug ('Queueing file %r' , file )
248258 yield MirrorFileAction (catalog = a .catalog ,
249259 source = a .source ,
250260 prefix = a .prefix ,
251261 file = file )
262+ else :
263+ log .info ('Not mirroring file to save cost: %r' , file )
252264 log .info ('Queued %d files in partition %r of source %r in catalog %r' ,
253265 len (files ), a .prefix , str (a .source ), a .catalog )
254266
0 commit comments