[SCM] ci-tooling packaging branch, master, updated. 4986315c301d24726cdc5c9ff1cc4670a81b20de

Harald Sitter apachelogger-guest at moszumanska.debian.org
Wed Oct 28 14:02:31 UTC 2015


Gitweb-URL: http://git.debian.org/?p=pkg-kde/ci-tooling.git;a=commitdiff;h=4986315

The following commit has been merged in the master branch:
commit 4986315c301d24726cdc5c9ff1cc4670a81b20de
Author: Harald Sitter <sitter at kde.org>
Date:   Wed Oct 28 15:01:55 2015 +0100

    add auto-updates in apt when we haven't updated in 5 minutes
    
    this is to force regular updates to reduce the risk of running into
    a 404
---
 lib/apt.rb                           | 17 ++++++++++++++++-
 test/test_apt.rb                     | 21 +++++++++++++++++++++
 test/test_qml_dependency_verifier.rb |  2 ++
 3 files changed, 39 insertions(+), 1 deletion(-)

diff --git a/lib/apt.rb b/lib/apt.rb
index 9615746..f88365d 100644
--- a/lib/apt.rb
+++ b/lib/apt.rb
@@ -75,6 +75,13 @@ module Apt
   module Abstrapt
     def self.run(cmd, operation, *caller_args)
       @log ||= Logger.new(STDOUT)
+      auto_update unless operation == 'update'
+      run_internal(cmd, operation, *caller_args)
+    end
+
+    private
+
+    def self.run_internal(cmd, operation, *caller_args)
       injection_args = []
       caller_args.delete_if do |arg|
         next false unless arg.is_a?(Hash)
@@ -93,7 +100,11 @@ module Apt
       system(cmd, *args)
     end
 
-    private
+    def self.auto_update
+      return unless @last_update.nil? || (Time.now - @last_update) >= (5 * 60)
+      @last_update = Time.now
+      Apt.update
+    end
 
     # @return [Array<String>] default arguments to inject into apt call
     def self.default_args
@@ -104,5 +115,9 @@ module Apt
       @default_args << '-o' << 'Debug::pkgProblemResolver=true'
       @default_args
     end
+
+    def self.reset
+      @last_update = nil
+    end
   end
 end
diff --git a/test/test_apt.rb b/test/test_apt.rb
index d08bdf1..977f0b5 100644
--- a/test/test_apt.rb
+++ b/test/test_apt.rb
@@ -8,6 +8,8 @@ class AptTest < TestCase
 
   def setup
     Apt::Repository.send(:reset)
+    # Disable automatic update
+    Apt::Abstrapt.send(:instance_variable_set, :@last_update, Time.now)
   end
 
   def test_repo
@@ -85,4 +87,23 @@ class AptTest < TestCase
       Apt::Key.add('abc')
     end
   end
+
+  def test_automatic_update
+    # Updates
+    Apt::Abstrapt.send(:instance_variable_set, :@last_update, nil)
+    assert_system([default_args + ['update'],
+                   default_args + %w(install abc)]) do
+      Apt.install('abc')
+    end
+    # Doesn't update if recent
+    Apt::Abstrapt.send(:instance_variable_set, :@last_update, Time.now)
+    assert_system([default_args + %w(install abc)]) do
+      Apt.install('abc')
+    end
+    # Doesn't update if update
+    Apt::Abstrapt.send(:instance_variable_set, :@last_update, nil)
+    assert_system([default_args + ['update']]) do
+      Apt.update
+    end
+  end
 end
diff --git a/test/test_qml_dependency_verifier.rb b/test/test_qml_dependency_verifier.rb
index 3904c2a..1c81a20 100644
--- a/test/test_qml_dependency_verifier.rb
+++ b/test/test_qml_dependency_verifier.rb
@@ -27,6 +27,8 @@ class QMLDependencyVerifierTest < TestCase
     LSB.instance_variable_set(:@hash, DISTRIB_CODENAME: 'vivid')
 
     Apt::Repository.send(:reset)
+    # Disable automatic update
+    Apt::Abstrapt.send(:instance_variable_set, :@last_update, Time.now)
   end
 
   def teardown

-- 
ci-tooling packaging



More information about the pkg-kde-commits mailing list