public inbox for gentoo-portage-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-portage-dev] [PATCH] egencache: stable use.local.desc mtime for rsync (bug 557192)
@ 2015-08-25  7:44 Zac Medico
  2015-08-25 16:34 ` [gentoo-portage-dev] [PATCH v2] " Zac Medico
  0 siblings, 1 reply; 5+ messages in thread
From: Zac Medico @ 2015-08-25  7:44 UTC (permalink / raw
  To: gentoo-portage-dev; +Cc: Zac Medico

Preserve mtime when the md5sum is identical.

X-Gentoo-Bug: 557192
X-Gentoo-Bug-url: https://bugs.gentoo.org/show_bug.cgi?id=557192
---
 bin/egencache | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/bin/egencache b/bin/egencache
index 5c00248..7ac1fba 100755
--- a/bin/egencache
+++ b/bin/egencache
@@ -7,6 +7,7 @@ from __future__ import print_function, unicode_literals
 
 import platform
 import signal
+import stat
 import sys
 # This block ensures that ^C interrupts are handled quietly.
 try:
@@ -487,6 +488,8 @@ class GenUseLocalDesc(object):
 	def run(self):
 		repo_path = self._portdb.porttrees[0]
 		ops = {'<':0, '<=':1, '=':2, '>=':3, '>':4}
+		prev_mtime = None
+		prev_md5 = None
 
 		if self._output is None or self._output != '-':
 			if self._output is None:
@@ -500,6 +503,12 @@ class GenUseLocalDesc(object):
 				desc_path = self._output
 
 			try:
+				prev_md5 = portage.checksum.perform_md5(desc_path)
+				prev_mtime = os.stat(desc_path)[stat.ST_MTIME]
+			except (portage.exception.FileNotFound, OSError):
+				pass
+
+			try:
 				if self._preserve_comments:
 					# Probe in binary mode, in order to avoid
 					# potential character encoding issues.
@@ -651,6 +660,11 @@ class GenUseLocalDesc(object):
 						output.write('%s:%s - %s\n' % (cp, flag, resdesc))
 
 		output.close()
+		if (prev_mtime is not None and
+			prev_md5 == portage.checksum.perform_md5(desc_path)):
+			# preserve mtime for rsync
+			os.utime(desc_path, (prev_mtime, prev_mtime))
+
 
 if sys.hexversion < 0x3000000:
 	_filename_base = unicode
-- 
2.4.6



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [gentoo-portage-dev] [PATCH v2] egencache: stable use.local.desc mtime for rsync (bug 557192)
  2015-08-25  7:44 [gentoo-portage-dev] [PATCH] egencache: stable use.local.desc mtime for rsync (bug 557192) Zac Medico
@ 2015-08-25 16:34 ` Zac Medico
  2015-08-26  1:30   ` Brian Dolbec
  2015-09-01 10:46   ` Michał Górny
  0 siblings, 2 replies; 5+ messages in thread
From: Zac Medico @ 2015-08-25 16:34 UTC (permalink / raw
  To: gentoo-portage-dev; +Cc: Zac Medico

Preserve mtime when the md5sum is identical.

X-Gentoo-Bug: 557192
X-Gentoo-Bug-url: https://bugs.gentoo.org/show_bug.cgi?id=557192
---
[PATCH v2] ensures exact integer mtime when there is not an existing file, for
consistency with the mtime preservation code.

 bin/egencache | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/bin/egencache b/bin/egencache
index 5c00248..4f4c715 100755
--- a/bin/egencache
+++ b/bin/egencache
@@ -7,6 +7,7 @@ from __future__ import print_function, unicode_literals
 
 import platform
 import signal
+import stat
 import sys
 # This block ensures that ^C interrupts are handled quietly.
 try:
@@ -487,6 +488,8 @@ class GenUseLocalDesc(object):
 	def run(self):
 		repo_path = self._portdb.porttrees[0]
 		ops = {'<':0, '<=':1, '=':2, '>=':3, '>':4}
+		prev_mtime = None
+		prev_md5 = None
 
 		if self._output is None or self._output != '-':
 			if self._output is None:
@@ -500,6 +503,12 @@ class GenUseLocalDesc(object):
 				desc_path = self._output
 
 			try:
+				prev_md5 = portage.checksum.perform_md5(desc_path)
+				prev_mtime = os.stat(desc_path)[stat.ST_MTIME]
+			except (portage.exception.FileNotFound, OSError):
+				pass
+
+			try:
 				if self._preserve_comments:
 					# Probe in binary mode, in order to avoid
 					# potential character encoding issues.
@@ -651,6 +660,17 @@ class GenUseLocalDesc(object):
 						output.write('%s:%s - %s\n' % (cp, flag, resdesc))
 
 		output.close()
+		if (prev_mtime is not None and
+			prev_md5 == portage.checksum.perform_md5(desc_path)):
+			# Preserve mtime for rsync.
+			mtime = prev_mtime
+		else:
+			# For portability, and consistency with the mtime preservation
+			# code, set mtime to an exact integer value.
+			mtime = int(time.time())
+
+		os.utime(desc_path, (mtime, mtime))
+
 
 if sys.hexversion < 0x3000000:
 	_filename_base = unicode
-- 
2.4.6



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [gentoo-portage-dev] [PATCH v2] egencache: stable use.local.desc mtime for rsync (bug 557192)
  2015-08-25 16:34 ` [gentoo-portage-dev] [PATCH v2] " Zac Medico
@ 2015-08-26  1:30   ` Brian Dolbec
  2015-09-01 10:46   ` Michał Górny
  1 sibling, 0 replies; 5+ messages in thread
From: Brian Dolbec @ 2015-08-26  1:30 UTC (permalink / raw
  To: gentoo-portage-dev

On Tue, 25 Aug 2015 09:34:16 -0700
Zac Medico <zmedico@gentoo.org> wrote:

> Preserve mtime when the md5sum is identical.
> 
> X-Gentoo-Bug: 557192
> X-Gentoo-Bug-url: https://bugs.gentoo.org/show_bug.cgi?id=557192
> ---
> [PATCH v2] ensures exact integer mtime when there is not an existing
> file, for consistency with the mtime preservation code.
> 
>  bin/egencache | 20 ++++++++++++++++++++
>  1 file changed, 20 insertions(+)
> 
> diff --git a/bin/egencache b/bin/egencache
> index 5c00248..4f4c715 100755
> --- a/bin/egencache
> +++ b/bin/egencache
> @@ -7,6 +7,7 @@ from __future__ import print_function,
> unicode_literals 
>  import platform
>  import signal
> +import stat
>  import sys
>  # This block ensures that ^C interrupts are handled quietly.
>  try:
> @@ -487,6 +488,8 @@ class GenUseLocalDesc(object):
>  	def run(self):
>  		repo_path = self._portdb.porttrees[0]
>  		ops = {'<':0, '<=':1, '=':2, '>=':3, '>':4}
> +		prev_mtime = None
> +		prev_md5 = None
>  
>  		if self._output is None or self._output != '-':
>  			if self._output is None:
> @@ -500,6 +503,12 @@ class GenUseLocalDesc(object):
>  				desc_path = self._output
>  
>  			try:
> +				prev_md5 =
> portage.checksum.perform_md5(desc_path)
> +				prev_mtime =
> os.stat(desc_path)[stat.ST_MTIME]
> +			except (portage.exception.FileNotFound,
> OSError):
> +				pass
> +
> +			try:
>  				if self._preserve_comments:
>  					# Probe in binary mode, in
> order to avoid # potential character encoding issues.
> @@ -651,6 +660,17 @@ class GenUseLocalDesc(object):
>  						output.write('%s:%s
> - %s\n' % (cp, flag, resdesc)) 
>  		output.close()
> +		if (prev_mtime is not None and
> +			prev_md5 ==
> portage.checksum.perform_md5(desc_path)):
> +			# Preserve mtime for rsync.
> +			mtime = prev_mtime
> +		else:
> +			# For portability, and consistency with the
> mtime preservation
> +			# code, set mtime to an exact integer value.
> +			mtime = int(time.time())
> +
> +		os.utime(desc_path, (mtime, mtime))
> +
>  
>  if sys.hexversion < 0x3000000:
>  	_filename_base = unicode

Looks Good :)

-- 
Brian Dolbec <dolsen>



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [gentoo-portage-dev] [PATCH v2] egencache: stable use.local.desc mtime for rsync (bug 557192)
  2015-08-25 16:34 ` [gentoo-portage-dev] [PATCH v2] " Zac Medico
  2015-08-26  1:30   ` Brian Dolbec
@ 2015-09-01 10:46   ` Michał Górny
  2015-09-01 16:09     ` Zac Medico
  1 sibling, 1 reply; 5+ messages in thread
From: Michał Górny @ 2015-09-01 10:46 UTC (permalink / raw
  To: gentoo-portage-dev, Zac Medico; +Cc: Zac Medico



Dnia 25 sierpnia 2015 18:34:16 CEST, Zac Medico <zmedico@gentoo.org> napisał(a):
>Preserve mtime when the md5sum is identical.

Sorry for being late to the party but wouldn't it be cleaner not to rewrite the file in the case?

>
>X-Gentoo-Bug: 557192
>X-Gentoo-Bug-url: https://bugs.gentoo.org/show_bug.cgi?id=557192
>---
>[PATCH v2] ensures exact integer mtime when there is not an existing
>file, for
>consistency with the mtime preservation code.
>
> bin/egencache | 20 ++++++++++++++++++++
> 1 file changed, 20 insertions(+)
>
>diff --git a/bin/egencache b/bin/egencache
>index 5c00248..4f4c715 100755
>--- a/bin/egencache
>+++ b/bin/egencache
>@@ -7,6 +7,7 @@ from __future__ import print_function, unicode_literals
> 
> import platform
> import signal
>+import stat
> import sys
> # This block ensures that ^C interrupts are handled quietly.
> try:
>@@ -487,6 +488,8 @@ class GenUseLocalDesc(object):
> 	def run(self):
> 		repo_path = self._portdb.porttrees[0]
> 		ops = {'<':0, '<=':1, '=':2, '>=':3, '>':4}
>+		prev_mtime = None
>+		prev_md5 = None
> 
> 		if self._output is None or self._output != '-':
> 			if self._output is None:
>@@ -500,6 +503,12 @@ class GenUseLocalDesc(object):
> 				desc_path = self._output
> 
> 			try:
>+				prev_md5 = portage.checksum.perform_md5(desc_path)
>+				prev_mtime = os.stat(desc_path)[stat.ST_MTIME]
>+			except (portage.exception.FileNotFound, OSError):
>+				pass
>+
>+			try:
> 				if self._preserve_comments:
> 					# Probe in binary mode, in order to avoid
> 					# potential character encoding issues.
>@@ -651,6 +660,17 @@ class GenUseLocalDesc(object):
> 						output.write('%s:%s - %s\n' % (cp, flag, resdesc))
> 
> 		output.close()
>+		if (prev_mtime is not None and
>+			prev_md5 == portage.checksum.perform_md5(desc_path)):
>+			# Preserve mtime for rsync.
>+			mtime = prev_mtime
>+		else:
>+			# For portability, and consistency with the mtime preservation
>+			# code, set mtime to an exact integer value.
>+			mtime = int(time.time())
>+
>+		os.utime(desc_path, (mtime, mtime))
>+
> 
> if sys.hexversion < 0x3000000:
> 	_filename_base = unicode

-- 
Best regards,
Michał Górny


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [gentoo-portage-dev] [PATCH v2] egencache: stable use.local.desc mtime for rsync (bug 557192)
  2015-09-01 10:46   ` Michał Górny
@ 2015-09-01 16:09     ` Zac Medico
  0 siblings, 0 replies; 5+ messages in thread
From: Zac Medico @ 2015-09-01 16:09 UTC (permalink / raw
  To: Michał Górny, gentoo-portage-dev

On 09/01/2015 03:46 AM, Michał Górny wrote:
> 
> 
> Dnia 25 sierpnia 2015 18:34:16 CEST, Zac Medico <zmedico@gentoo.org> napisał(a):
>> Preserve mtime when the md5sum is identical.
> 
> Sorry for being late to the party but wouldn't it be cleaner not to rewrite the file in the case?

Yes, but the code is kind of a mess because it opens the file in 3
different places (related to comment header preservation code). So, I
thought it would be best to do a patch with minimal changes first.
-- 
Thanks,
Zac


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-09-01 16:09 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-08-25  7:44 [gentoo-portage-dev] [PATCH] egencache: stable use.local.desc mtime for rsync (bug 557192) Zac Medico
2015-08-25 16:34 ` [gentoo-portage-dev] [PATCH v2] " Zac Medico
2015-08-26  1:30   ` Brian Dolbec
2015-09-01 10:46   ` Michał Górny
2015-09-01 16:09     ` Zac Medico

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox