lib/d3/client/receipt.rb in depot3-3.0.9 vs lib/d3/client/receipt.rb in depot3-3.0.11
- old
+ new
@@ -103,11 +103,11 @@
:status,
:removable,
:pre_remove_script_id,
:post_remove_script_id,
:expiration,
- :expiration_path,
+ :expiration_paths,
:prohibiting_process
]
################## Class Variables #################
@@ -146,10 +146,11 @@
# get the lock if needed
self.get_datastore_lock(lock_timeout) if rw
@@installed_rcpts = DATASTORE.file? ? YAML.load(DATASTORE.read) : {}
+ @@installed_rcpts ||= {}
D3.log "Receipts loaded", :debug
end # seld.load_receipts
### Reload the existing rcpt database
@@ -160,11 +161,11 @@
### @param lock_timeout[Integer] How many seconds to keep trying to get the
### read-write lock, when loading read-write.
###
### @return [void]
###
- def self.reload_receipts(rw = false, lock_timeout = DATASTORE_LOCK_TIMEOUT)
+ def self.reload_receipts (rw = false, lock_timeout = DATASTORE_LOCK_TIMEOUT)
# if we haven't loaded them at all yet, just do that.
unless @@installed_rcpts
self.load_receipts rw, lock_timeout
return
@@ -181,10 +182,11 @@
self.release_datastore_lock if @@got_lock
end
# reload it
@@installed_rcpts = DATASTORE.file? ? YAML.load(DATASTORE.read) : {}
+ @@installed_rcpts ||= {}
D3.log "Receipts reloaded", :debug
end # self.reload_receipts
### Write existing rcpt database to disk
###
@@ -468,12 +470,12 @@
:jamf_rcpt_file => d3_pkg.receipt,
:apple_pkg_ids => d3_pkg.apple_receipt_data.map{|r| r[:apple_pkg_id]},
:removable => d3_pkg.removable,
:pre_remove_script_id => d3_pkg.pre_remove_script_id,
:post_remove_script_id => d3_pkg.post_remove_script_id,
- :expiraation => d3_pkg.expiraation,
- :expiraation_path => d3_pkg.expiraation_path
+ :expiration => d3_pkg.expiration,
+ :expiration_paths => d3_pkg.expiration_paths
)
end # .each do |d3_pkg|
@@installed_rcpts = new_rcpts
@@ -517,15 +519,15 @@
# basename? If so, d3 sync will not update it, but a manual
# d3 install still can, and will re-enable syncs
attr_accessor :frozen
# @return [Time, nil] When was this app last used.
- # nil if never checked, or no @expiration_path
+ # nil if never checked, or no @expiration_paths
attr_reader :last_usage
# @return [Time, nil] When was @last_usage updated?
- # nil if never checked, or no @expiration_path
+ # nil if never checked, or no @expiration_paths
attr_reader :last_usage_as_of
################# Constructor #################
### Args are:
@@ -577,11 +579,11 @@
@frozen = args[:frozen]
@pre_remove_script_id = args[:pre_remove_script_id]
@post_remove_script_id = args[:post_remove_script_id]
@expiration = args[:expiration].to_i
- @expiration_path = args[:expiration_path]
+ @expiration_paths = args[:expiration_paths]
@custom_expiration = args[:custom_expiration]
@manually_installed = (@admin != D3::AUTO_INSTALL_ADMIN)
@package_type = @jamf_rcpt_file.to_s.end_with?(".dmg") ? :dmg : :pkg
@@ -805,11 +807,11 @@
@apple_pkg_ids = d3_pkg.apple_receipt_data.map{|r| r[:apple_pkg_id]}
@removable = d3_pkg.removable
@manually_installed = (@admin != D3::AUTO_INSTALL_ADMIN)
@package_type = @jamf_rcpt_file.end_with?(".dmg") ? :dmg : :pkg
@expiration = d3_pkg.expiration
- @expiration_path = d3_pkg.expiration_path
+ @expiration_paths = d3_pkg.expiration_paths
end # repair rcpt
### Is this rcpt frozen?
###
@@ -858,12 +860,12 @@
###
### @param new_val[Pathname,String] The new expiration path
###
### @return [void]
###
- def expiration_path= (new_val)
- @expiration_path = Pathname.new new_val
+ def expiration_paths= (new_val)
+ @expiration_paths = new_val
end
### Set a new prohibiting process
def prohibiting_process=(new_val)
@prohibiting_process = new_val
@@ -928,11 +930,11 @@
if @package_type == :pkg and @apple_pkg_ids
deets += <<-END_DEETS
Apple.pkg ids: #{@apple_pkg_ids.join(', ')}
END_DEETS
end
- if @expiration_path
+ if @expiration_paths
if @expiration.to_i > 0
lu = last_usage
if lu.nil?
last_usage_display = "Unknonwn"
elsif lu == @installed_at
@@ -941,11 +943,11 @@
last_usage_display = "#{lu.strftime '%Y-%m-%d %H:%M:%S'} (#{days_since_last_usage} days ago)"
end # if my_last_usage == @installed_at
deets += <<-END_DEETS
Expiration period: #{@expiration} days#{@custom_expiration ? ' (custom)' : ''}
-Expiration path: #{@expiration_path}
+Expiration path(s): #{D3::Database::ARRAY_OF_PATHNAMES_TO_COMMA_STRING.call @expiration_paths}
Last brought to foreground: #{last_usage_display}
END_DEETS
end # if exp > 0
end # if exp path
return deets
@@ -968,12 +970,12 @@
# gotta be expirable
return false if @expiration.nil? or @expiration == 0
# gotta have an expiration path
- unless @expiration_path
- D3.log "Not expiring #{edition} because: No Expiration Path for #{edition}", :debug
+ if @expiration_paths.empty?
+ D3.log "Not expiring #{edition} because: No Expiration Path(s) for #{edition}", :debug
return false
end
# must have up-to-date last usage data
# this also checks for usage dir existence and plist age
@@ -1046,11 +1048,11 @@
D3::Client.unset_env :expiring
end
return deleted? ? edition : nil
end # expire
- ### Return the number of days since the last usage for the @expiration_path
+ ### Return the number of days since the last usage for the @expiration_paths
### for this receipt
###s
### Returns nil if last_usage is nil
###
### See also {#last_usage}
@@ -1077,23 +1079,23 @@
###
### @return [Time,nil] The last usage date, or nil if no
### expiration path or the data wasn't retrievable.
###
def last_usage
- return nil unless @expiration_path
+ return nil unless @expiration_paths
now = Time.now
# if it's in the foreground right now, return [now, 0]
fgnd_path = D3::Client.foreground_executable_path
if fgnd_path
- now_in_forground = (fgnd_path.to_s == @expiration_path.to_s.chomp('/'))
+ now_in_foreground = @expiration_paths.select{|p| fgnd_path == p}.length > 0
else
- now_in_forground = nil
+ now_in_foreground = nil
end
- if now_in_forground
+ if now_in_foreground
@last_usage = now
@last_usage_as_of = now
return @last_usage
end
@@ -1115,16 +1117,17 @@
if app_usage_update_age > MAX_APP_USAGE_UPDATE_AGE
D3.log "Last app usage update more than #{MAX_APP_USAGE_UPDATE_AGE} seconds ago.", :debug
return nil
end
- # loop through the plists, get the newest usage time for this
+ # loop through the plists, get the newest usage time for this
# expiration path, and append it to all_usages
all_usages = []
plists.each do |plist|
usage_times = D3.parse_plist plist
- my_usage_keys = usage_times.keys.select{|k| k.start_with? @expiration_path.to_s }
- all_usages << my_usage_keys.map{|k| usage_times[k].to_time }.max
+ my_usage_keys = usage_times.keys.map{|p| Pathname.new(p)}
+ exp_paths_with_usage = @expiration_paths & my_usage_keys
+ exp_paths_with_usage.each{|p| all_usages << usage_times[p] }
end # do plist
@last_usage = all_usages.compact.max
# if never been used, last usage is the install date