Class: Vagrant::Node::BoxAddAction

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-node/actions/boxadd.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ BoxAddAction

Returns a new instance of BoxAddAction.



10
11
12
# File 'lib/vagrant-node/actions/boxadd.rb', line 10

def initialize(app, env)
  @app    = app          
end

Instance Method Details

#call(env) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/vagrant-node/actions/boxadd.rb', line 95

def call(env)


  while ObManager.instance.dbmanager.are_boxes_queued
    download_boxes(env)
  end

  
  # Success, we added a box!
  #env[:ui].success(
   # I18n.t("vagrant.actions.box.add.added", name: added_box.name, provider: added_box.provider))

  # Carry on!
  @app.call(env)
end

#download_boxes(env) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/vagrant-node/actions/boxadd.rb', line 14

def download_boxes(env)
  @temp_path = env[:tmp_path].join("box" + Time.now.to_i.to_s)
  
  result=ObManager.instance.dbmanager.get_box_to_download          
  
  next_id=result["id"]          
  
  next_box_name = result["box_name"]

  url = result["box_url"]
  
  if File.file?(url) || url !~ /^[a-z0-9]+:.*$/i          
    file_path = File.expand_path(url)
    file_path = Util::Platform.cygwin_windows_path(file_path)
    url = "file:#{file_path}"
  end

  downloader_options = {}
  downloader_options[:callback] = env[:callback]
  downloader_options[:insecure] = env[:box_download_insecure]
  downloader_options[:ui] = env[:ui]
  downloader_options[:db] = env[:db]
  downloader_options[:box_name] = next_box_name




  # Download the box to a temporary path. We store the temporary
  # path as an instance variable so that the `#recover` method can
  # access it.
  #env[:ui].info(I18n.t("vagrant.actions.box.download.downloading"))
  

  begin
    downloader = Util::Downloader.new(url, @temp_path, downloader_options)             
    downloader.download!            
    
  rescue Errors::DownloaderInterrupted
    # The downloader was interrupted, so just return, because that
    # means we were interrupted as well.
    #env[:ui].info(I18n.t("vagrant.actions.box.download.interrupted"))
    return          
  rescue Errors::DownloaderError => msg
    return
  end

  # Add the box          
  added_box = nil
  error=false

  begin
    
    #last_id=env[:db].add_box_uncompression(env[:box_name],url)        
    ObManager.instance.dbmanager.add_box_uncompression(next_id)
      
    added_box = env[:box_collection].add(
      @temp_path, next_box_name, env[:box_provider], env[:box_force])
    
    error=false
  rescue Vagrant::Errors::BoxUpgradeRequired
    
    error=true
    # Upgrade the box
    #@db.set_box_uncompression_error(last_id)            

    env[:box_collection].upgrade(next_box_name)

    # Try adding it again
    retry
  end


  
  ObManager.instance.dbmanager.clear_box_uncompression(next_id)

  #env[:db].close_db_connection
  # Call the 'recover' method in all cases to clean up the
  # downloaded temporary file.
  recover(env)
end

#recover(env) ⇒ Object



111
112
113
114
115
# File 'lib/vagrant-node/actions/boxadd.rb', line 111

def recover(env)
  if @temp_path && File.exist?(@temp_path)
    File.unlink(@temp_path)
  end
end