[cedar-backup-svn] SF.net SVN: cedar-backup: [879] cedar-backup2/trunk
Brought to you by:
pronovic
|
From: <pro...@us...> - 2008-03-20 04:00:31
|
Revision: 879
http://cedar-backup.svn.sourceforge.net/cedar-backup/?rev=879&view=rev
Author: pronovic
Date: 2008-03-19 21:00:23 -0700 (Wed, 19 Mar 2008)
Log Message:
-----------
Clean up filesystem code that deals with file age, and improve unit tests.
Modified Paths:
--------------
cedar-backup2/trunk/CedarBackup2/filesystem.py
cedar-backup2/trunk/CedarBackup2/testutil.py
cedar-backup2/trunk/CedarBackup2/util.py
cedar-backup2/trunk/Changelog
Modified: cedar-backup2/trunk/CedarBackup2/filesystem.py
===================================================================
--- cedar-backup2/trunk/CedarBackup2/filesystem.py 2008-03-20 02:42:35 UTC (rev 878)
+++ cedar-backup2/trunk/CedarBackup2/filesystem.py 2008-03-20 04:00:23 UTC (rev 879)
@@ -52,6 +52,7 @@
import os
import re
import sha
+import math
import logging
import tarfile
@@ -1305,8 +1306,9 @@
for entry in self[:]:
if os.path.isfile(entry) and not os.path.islink(entry):
try:
- age = calculateFileAge(entry)
- if age < daysOld:
+ ageInDays = calculateFileAge(entry)
+ ageInWholeDays = math.floor(ageInDays)
+ if ageInWholeDays < daysOld:
removed += 1
self.remove(entry)
except OSError:
Modified: cedar-backup2/trunk/CedarBackup2/testutil.py
===================================================================
--- cedar-backup2/trunk/CedarBackup2/testutil.py 2008-03-20 02:42:35 UTC (rev 878)
+++ cedar-backup2/trunk/CedarBackup2/testutil.py 2008-03-20 04:00:23 UTC (rev 879)
@@ -219,16 +219,25 @@
def changeFileAge(filename, subtract=None):
"""
Changes a file age using the C{os.utime} function.
+
+ @note: Some platforms don't seem to be able to set an age precisely. As a
+ result, whereas we might have intended to set an age of 86400 seconds, we
+ actually get an age of 86399.375 seconds. When util.calculateFileAge()
+ looks at that the file, it calculates an age of 0.999992766204 days, which
+ then gets truncated down to zero whole days. The tests get very confused.
+ To work around this, I always subtract off one additional second as a fudge
+ factor. That way, the file age will be I{at least} as old as requested
+ later on.
+
@param filename: File to operate on.
@param subtract: Number of seconds to subtract from the current time.
@raise ValueError: If a path cannot be encoded properly.
"""
filename = encodePath(filename)
- if subtract is None:
- os.utime(filename, None)
- else:
- newTime = time.time() - subtract
- os.utime(filename, (newTime, newTime))
+ newTime = time.time() - 1;
+ if subtract is not None:
+ newTime -= subtract
+ os.utime(filename, (newTime, newTime))
###########################
Modified: cedar-backup2/trunk/CedarBackup2/util.py
===================================================================
--- cedar-backup2/trunk/CedarBackup2/util.py 2008-03-20 02:42:35 UTC (rev 878)
+++ cedar-backup2/trunk/CedarBackup2/util.py 2008-03-20 04:00:23 UTC (rev 879)
@@ -8,7 +8,7 @@
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
-# Copyright (c) 2004-2007 Kenneth J. Pronovici.
+# Copyright (c) 2004-2008 Kenneth J. Pronovici.
# All rights reserved.
#
# Portions copyright (c) 2001, 2002 Python Software Foundation.
@@ -119,9 +119,9 @@
BYTES_PER_MBYTE = BYTES_PER_KBYTE * KBYTES_PER_MBYTE
BYTES_PER_GBYTE = BYTES_PER_MBYTE * MBYTES_PER_GBYTE
-SECONDS_PER_MINUTE = 60
-MINUTES_PER_HOUR = 60
-HOURS_PER_DAY = 24
+SECONDS_PER_MINUTE = 60.0
+MINUTES_PER_HOUR = 60.0
+HOURS_PER_DAY = 24.0
SECONDS_PER_DAY = SECONDS_PER_MINUTE * MINUTES_PER_HOUR * HOURS_PER_DAY
UNIT_BYTES = 0
@@ -1415,13 +1415,14 @@
@param file: Path to a file on disk.
- @return: Age of the file in days.
+ @return: Age of the file in days (possibly fractional).
@raise OSError: If the file doesn't exist.
"""
currentTime = int(time.time())
fileStats = os.stat(file)
lastUse = max(fileStats.st_atime, fileStats.st_mtime) # "most recent" is "largest"
- ageInDays = (currentTime - lastUse) / SECONDS_PER_DAY
+ ageInSeconds = currentTime - lastUse
+ ageInDays = ageInSeconds / SECONDS_PER_DAY
return ageInDays
Modified: cedar-backup2/trunk/Changelog
===================================================================
--- cedar-backup2/trunk/Changelog 2008-03-20 02:42:35 UTC (rev 878)
+++ cedar-backup2/trunk/Changelog 2008-03-20 04:00:23 UTC (rev 879)
@@ -1,8 +1,14 @@
-Version 2.16.0 unreleased
+Version 2.16.1 unreleased
* Change suggested execution index for Capacity in manual.
* Fix utiltests.TestFunctions.testNullDevice_001() for Windows 2000.
* Fix typo in filesystemtests.TestFilesystemList.testRemoveLinks_002().
+ * Clean up filesystem code that deals with file age, and improve unit tests.
+ - Some platforms apparently cannot set file ages precisely
+ - Change calculateFileAge() to use floats throughout, which is safer
+ - Change removeYoungFiles() to explicitly check on whole days
+ - Put a 1-second fudge factor into unit tests when setting file ages
+ - This is really a test-only bug, but better safe than sorry
Version 2.16.0 18 Mar 2008
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|