Skip to content

Commit

Permalink
Move tem dir to volume directory (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
yzhoubk authored Dec 21, 2023
1 parent dc557f9 commit f980316
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ services:
GEOSERVER_URL: http://admin:geoserver@geoserver:8080/geoserver/rest/
SOLR_URL: http://solr:8983/solr/geodata-test
SPATIAL_ROOT: data/spatial/
PROCESSING_ROOT: data/processing/
restart: no
volumes:
- ./:/opt/app:delegated
Expand Down
5 changes: 2 additions & 3 deletions lib/gingr/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,8 @@ def unpack(zipfile)
Config.default_options[:spatial_root])
DataHandler.geoserver_root = options[:geoserver_root] || ENV.fetch('GEOSERVER_ROOT',
Config.default_options[:geoserver_root])

temp_path = File.join(Dir.pwd, 'tmp')
DataHandler.extract_and_move(zipfile_path, temp_path)
DataHandler.processing_root = ENV.fetch('PROCESSING_ROOT', Config.default_options[:processing_root])
DataHandler.extract_and_move(zipfile_path)
end

desc 'all',
Expand Down
1 change: 1 addition & 0 deletions lib/gingr/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module Config
spatial_url: 'https://spatial.lib.berkeley.edu',
spatial_root: 'data/spatial/',
geoserver_root: 'data/geoserver/',
processing_root: 'data/processing/',
solr_url: 'http://solr:8983/solr/geodata-test'
}

Expand Down
17 changes: 9 additions & 8 deletions lib/gingr/data_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,23 @@ module DataHandler

@spatial_root = ''
@geoserver_root = ''
@processing_root = ''

class << self
attr_accessor :spatial_root, :geoserver_root
attr_accessor :spatial_root, :geoserver_root, :processing_root

def extract_and_move(zip_file, to_dir_path)
extract_to_path = extract_zipfile(zip_file, to_dir_path)
def extract_and_move(zip_file)
extract_to_path = extract_zipfile(zip_file)

geofile_ingestion_dir_path = move_files(extract_to_path)
{ extract_to_path:, geofile_name_hash: get_geofile_name_hash(geofile_ingestion_dir_path) }
end

def extract_zipfile(zip_file, to_dir_path)
extracted_to_path = clr_subdirectory(zip_file, to_dir_path)
def extract_zipfile(zip_file, to_dir = @processing_root)
extracted_to_path = clr_subdirectory(zip_file)
Zip::File.open(zip_file) do |zip|
zip.each do |entry|
entry_path = File.join(to_dir_path, entry.name)
entry_path = File.join(to_dir, entry.name)
entry.extract(entry_path) { true }
end
end
Expand Down Expand Up @@ -55,9 +56,9 @@ def move_a_record(dir_path)
end

# remove the subdirectory if it exists
def clr_subdirectory(zip_file, to_dir_path)
def clr_subdirectory(zip_file)
subdir_name = File.basename(zip_file, '.*')
subdir_path = File.join(to_dir_path, subdir_name)
subdir_path = File.join(@processing_root, subdir_name)
FileUtils.rm_r(subdir_path) if File.directory? subdir_path
subdir_path
rescue Errno::EACCES
Expand Down

0 comments on commit f980316

Please sign in to comment.