]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfsprogs: fix utcnow deprecation warning in xfs_scrub_all.py
authorChristian Kujau <lists@nerdbynature.de>
Tue, 26 Aug 2025 16:06:26 +0000 (18:06 +0200)
committerAndrey Albershteyn <aalbersh@kernel.org>
Mon, 8 Sep 2025 11:25:52 +0000 (13:25 +0200)
Running xfs_scrub_all under Python 3.13.5 prints the following warning:

----------------------------------------------
$ /usr/sbin/xfs_scrub_all --auto-media-scan-stamp \
   /var/lib/xfsprogs/xfs_scrub_all_media.stamp \
   --auto-media-scan-interval 1d
/usr/sbin/xfs_scrub_all:489: DeprecationWarning:
datetime.datetime.utcnow() is deprecated and scheduled for removal in a
future version. Use timezone-aware objects to represent datetimes in UTC:
datetime.datetime.now(datetime.UTC).
  dt = datetime.utcnow()
Automatically enabling file data scrub.
----------------------------------------------

Python documentation for context:
https://docs.python.org/3/library/datetime.html#datetime.datetime.utcnow

Fix this by using datetime.now() instead.

NB: Debian/13 ships Python 3.13.5 and has a xfs_scrub_all.timer active,
I'd assume that many systems will have that warning now in their logs :-)

Signed-off-by: Christian Kujau <lists@nerdbynature.de>
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
scrub/xfs_scrub_all.py.in

index 515cc144414de652d997a2a69ddaa38ed613130d..ce251daea6a5d54dc514ce6b458cad116d79b5ba 100644 (file)
@@ -493,12 +493,6 @@ def scan_interval(string):
                return timedelta(seconds = float(string[:-1]))
        return timedelta(seconds = int(string))
 
-def utcnow():
-       '''Create a representation of the time right now, in UTC.'''
-
-       dt = datetime.utcnow()
-       return dt.replace(tzinfo = timezone.utc)
-
 def enable_automatic_media_scan(args):
        '''Decide if we enable media scanning automatically.'''
        already_enabled = args.x
@@ -515,7 +509,7 @@ def enable_automatic_media_scan(args):
        else:
                try:
                        last_run = p.stat().st_mtime
-                       now = utcnow().timestamp()
+                       now = datetime.now(timezone.utc).timestamp()
                        res = last_run + interval.total_seconds() < now
                except FileNotFoundError:
                        res = True