2013-07-05 17:08:09 +01:00
|
|
|
class PlatformContent
|
|
|
|
|
|
|
|
attr_reader :path
|
|
|
|
|
|
|
|
def initialize(platform, path)
|
|
|
|
@platform, @path = platform, path
|
|
|
|
end
|
|
|
|
|
|
|
|
def build_list
|
|
|
|
return @build_list if !!@build_list
|
2013-07-24 11:37:25 +01:00
|
|
|
return nil if @path !~ /\/(release|updates)+\/[\w\-\.]+$/
|
|
|
|
return nil unless repository_name = @path.match(/\/[\w]+\/(release|updates)\//)
|
2013-07-05 17:08:09 +01:00
|
|
|
repository_name = repository_name[0].gsub(/\/(release|updates)\/$/, '').gsub('/', '')
|
|
|
|
|
2014-01-21 04:51:49 +00:00
|
|
|
repository = @platform.repositories.where(name: repository_name).first
|
2013-07-05 17:08:09 +01:00
|
|
|
return nil unless repository
|
2014-01-21 04:51:49 +00:00
|
|
|
|
2013-07-05 17:08:09 +01:00
|
|
|
if @platform.main?
|
|
|
|
build_for_platform = @platform
|
|
|
|
else
|
2013-07-24 11:37:25 +01:00
|
|
|
bfp_name = @path.match(/\/#{@platform.name}\/repository\/[\w]+\//)
|
2013-07-05 17:08:09 +01:00
|
|
|
return nil unless bfp_name
|
|
|
|
bfp_name = bfp_name[0].gsub(/\/#{@platform.name}\/repository\//, '').gsub('/', '')
|
2014-03-18 13:58:51 +00:00
|
|
|
build_for_platform = Platform.main.find_by name: bfp_name
|
2013-07-05 17:08:09 +01:00
|
|
|
return nil unless build_for_platform
|
|
|
|
end
|
|
|
|
|
|
|
|
@build_list = BuildList.for_status(BuildList::BUILD_PUBLISHED)
|
|
|
|
.for_platform(build_for_platform)
|
|
|
|
.scoped_to_save_platform(@platform)
|
2014-01-21 04:51:49 +00:00
|
|
|
.where(save_to_repository_id: repository)
|
|
|
|
.where(build_list_packages: {fullname: name, actual: true})
|
2013-07-05 17:08:09 +01:00
|
|
|
.joins(:packages)
|
|
|
|
.last
|
|
|
|
|
|
|
|
return @build_list
|
|
|
|
end
|
|
|
|
|
|
|
|
def name
|
|
|
|
@name ||= @path.gsub(/.*#{File::SEPARATOR}/, '')
|
|
|
|
end
|
|
|
|
|
|
|
|
def size
|
2013-10-02 11:01:48 +01:00
|
|
|
@size ||= File.size(@path) rescue nil
|
2013-07-05 17:08:09 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def is_folder?
|
2013-07-24 11:37:25 +01:00
|
|
|
@is_folder.nil? ? (@is_folder = File.directory?(@path)) : @is_folder
|
2013-07-05 17:08:09 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def download_url
|
2014-05-16 22:53:04 +01:00
|
|
|
"#{APP_CONFIG['downloads_url']}/#{@platform.name}#{subpath}"
|
|
|
|
end
|
|
|
|
|
|
|
|
def subpath
|
|
|
|
@subpath ||= @path.gsub(/^#{@platform.path}/, '')
|
2013-07-05 17:08:09 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.find_by_platform(platform, path, term)
|
2013-07-08 16:08:55 +01:00
|
|
|
# Strip out the non-ascii character
|
|
|
|
term = (term || '').strip.gsub(/[\\\/]+/, '')
|
2014-03-11 07:39:25 +00:00
|
|
|
.gsub(/[^\w\-\+\.]/, '_')
|
2013-07-08 16:08:55 +01:00
|
|
|
|
2014-05-20 22:15:06 +01:00
|
|
|
path = sanitize_path(path)
|
2013-07-05 17:08:09 +01:00
|
|
|
results = Dir.glob(File.join(platform.path, path, "*#{term}*"))
|
|
|
|
if term
|
|
|
|
results = results.sort_by(&:length)
|
|
|
|
else
|
|
|
|
results = results.sort
|
|
|
|
end
|
|
|
|
results.map{ |p| PlatformContent.new(platform, p) }
|
|
|
|
end
|
|
|
|
|
2014-05-20 22:15:06 +01:00
|
|
|
def self.remove_file(platform, path)
|
|
|
|
path = File.join(platform.path, sanitize_path(path))
|
|
|
|
FileUtils.rm_f(path) if File.exist?(path)
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.sanitize_path(path)
|
|
|
|
path.split(File::SEPARATOR).map(&:strip).select(&:present?)
|
|
|
|
.map{ |p|
|
|
|
|
# Strip out the non-ascii character
|
|
|
|
p.gsub(/[\\\/]+/, '')
|
|
|
|
.gsub(/^[\.]+/, '')
|
|
|
|
.gsub(/[^\w\-\.]/, '_')
|
|
|
|
}.join(File::SEPARATOR)
|
|
|
|
end
|
|
|
|
|
2013-07-05 17:08:09 +01:00
|
|
|
end
|