require "ReverseBuildChecker.rb"
require "CommonJob.rb"
require "BuildServerException.rb"
+require "FileUtil"
class BuildJob < CommonJob
base_package_name= File.basename(local_path, "#{cos}#{ext}")
@log.info( "Copying compatible package:#{local_path}", Log::LV_USER)
@log.info( "Creating package file ... #{base_package_name}#{@os}#{ext}", Log::LV_USER)
- FileUtils.ln local_path, "#{@source_path}/#{base_package_name}#{@os}#{ext}", :force => true
+ #FileUtils.ln local_path, "#{@source_path}/#{base_package_name}#{@os}#{ext}", :force => true
+ if not FileUtil.safeLink(local_path, "#{@source_path}/#{base_package_name}#{@os}#{ext}") then
+ @log.error("Failed to link file [#{local_path}] to [#{@source_path}/#{base_package_name}#{@os}#{ext}]")
+ end
else
@log.info( "Downloading compatible package:#{pkg_name}(#{cos})", Log::LV_USER)
loc = @pkgsvr_client.download(pkg_name, cos, false)
binpkg_path_list.each do |file|
@result_files.push File.basename(file)
@log.info( " * #{file}", Log::LV_USER)
- FileUtils.ln(file,"#{dst_path}/", :force => true)
+ #FileUtils.ln(file,"#{dst_path}/", :force => true)
+ if not FileUtil.safeLink(file,"#{dst_path}/") then
+ @log.error("Failed to link file [#{file}] to [#{dst_path}]")
+ end
end
end
require "JobLog.rb"
require "mail.rb"
require "CommonJob.rb"
+require "FileUtil"
class MultiBuildJob < CommonJob
binpkg_path_list.each do |file|
@result_files.push File.basename(file)
@log.info( " * #{file}", Log::LV_USER)
- FileUtils.ln(file,"#{dst_path}/", :force => true)
+ #FileUtils.ln(file,"#{dst_path}/", :force => true)
+ if not FileUtil.safeLink(file,"#{dst_path}/") then
+ @log.error("Failed to link file [#{file}] to [#{dst_path}]")
+ end
end
end
require "CommonJob.rb"
require "JobLog.rb"
require "BuildServerException.rb"
+require "FileUtil"
class RegisterPackageJob < CommonJob
FileUtils.mv(@local_path, @file_path)
FileUtils.rm_rf("#{File.dirname(@local_path)}")
else
- FileUtils.ln(@local_path, @file_path, :force => true)
+ #FileUtils.ln(@local_path, @file_path, :force => true)
+ if not FileUtil.safeLink(@local_path, @file_path) then
+ @log.error("Failed to link file [#{@local_path}] to [#{@file_path}]")
+ end
end
# check if the os is supported by build server
# make new package file for compatible OS
newfile = "#{@pkg_name}_#{@pkg_version}_#{os}.zip"
@log.info( "Copying #{@filename} to #{newfile}" )
- FileUtils.ln(@file_path,"#{@source_path}/#{newfile}",:force => true)
+ #FileUtils.ln(@file_path,"#{@source_path}/#{newfile}",:force => true)
+ if not FileUtil.safeLink(@file_path,"#{@source_path}/#{newfile}") then
+ @log.error("Failed to link file [#{@file_path}] to [#{@source_path}/#{newfile}]")
+ end
# reverse check
if not @no_reverse then
require "utils"
require "PackageManifest"
require "log"
+require "FileUtil"
class Builder
private_class_method :new
return true
end
- FileUtils.ln(src, tar,:force => true)
+ #FileUtils.ln(src, tar,:force => true)
+ if not FileUtil.safeLink(src, tar) then
+ @log.error("Failed to link file #{src} to #{tar}")
+ return false
+ end
end
return true
return true
end
- FileUtils.ln(src, tar,:force => true)
+ #FileUtils.ln(src, tar,:force => true)
+ if not FileUtil.safeLink(src, tar) then
+ @log.error("Failed to link file #{src} to #{tar}")
+ return false
+ end
end
return true
end
=end
$LOAD_PATH.unshift File.dirname(__FILE__)
+$LOAD_PATH.unshift File.dirname(File.dirname(__FILE__))+"/common"
require "log"
require "socket"
require 'timeout'
require 'thread'
require "FileTransferViaFTP"
require "FileTransferViaDirect"
+require "FileUtil"
ATTEMPTS = ["first", "second", "third"]
# if hit , touch and copy
FileUtils.touch cache_file
- FileUtils.ln(cache_file, dst_file, :force => true)
-
- found = true
+ #FileUtils.ln(cache_file, dst_file, :force => true)
+ if (FileUtil.safeLink(cache_file, dst_file)) then
+ found = true
+ else
+ @log.error "Failed to link file [#{cache_file}] to [#{dst_file}]"
+ end
end
# refresh cache dir
file_name = File.basename(dst_file)
cache_file = "#{@cache_dir}/#{file_name}"
@download_cache_mutex.synchronize do
- # copy & touch
- FileUtils.ln(dst_file, cache_file, :force => true)
+ # copy & touch
+ #FileUtils.ln(dst_file, cache_file, :force => true)
+ if not FileUtil.safeLink(dst_file, cache_file) then
+ @log.error "Failed to link file [#{dst_file}] to [#{cache_file}]"
+ end
FileUtils.touch cache_file
end
end
return false
end
end
-
-end
\ No newline at end of file
+
+ public
+ def FileUtil.safeLink(target, linkname, force = true)
+ # linkname can be a file or a directory
+ #
+ # if linkname does not exist, it sould be a filename.
+ # - File.dirname(linkpath) should exists and be a directory.
+ # if linkname does exist, it should be a directory.
+ # - if it is a file, FileUtils.ln() will be a error.
+ # - if it is a file, FileUtils.cp() will be finished successfully.
+ linkpath = linkname
+ if not File.exist? linkname then
+ linkpath = File.dirname(linkname)
+ end
+
+ # both target and linkpath should exist.
+ if not File.exist? target and not File.exist? linkpath then
+ return false
+ end
+
+ # compare device between target and linkpath
+ # - execute ln if it is same device
+ # - execute cp if it is different device
+ target_device = File.stat(target).dev
+ linkpath_device = File.stat(linkpath).dev
+ if target_device.eql? linkpath_device then
+ FileUtils.ln(target, linkname, :force => force)
+ else
+ FileUtils.cp(target, linkname)
+ end
+
+ return true
+ end
+end
require "SnapshotController"
require "ChangeLogController"
require 'PackageServerConstants'
-
-
+require "FileUtil"
$update_mutex = Mutex.new
$get_snapshot_mutex = Mutex.new
@log.info "Entering cache sync",Log::LV_USER
cached_filepath = get_cached_filepath(filename, pkg_checksum, pkg_size)
if not cached_filepath.nil? and File.exist? cached_filepath then
- FileUtils.ln(cached_filepath, location, :force => true)
- downloaded_file_path = File.join(location, File.basename(cached_filepath))
+ #FileUtils.ln(cached_filepath, location, :force => true)
+ if (FileUtil.safeLink(cached_filepath, location)) then
+ downloaded_file_path = File.join(location, File.basename(cached_filepath))
+ end
end
ensure
Utils.file_unlock(lock) if not lock.nil?
@log.info " [path: #{@download_path}]"
if not File.exist? cachefile then
- FileUtils.ln(filepath, @download_path, :force => true)
+ #FileUtils.ln(filepath, @download_path, :force => true)
+ if not FileUtil.safeLink(filepath, @download_path) then
+ @log.info "Failed to link file [#{filepath}] to "
+ @log.info " [#{@download_path}]"
+ end
end
if not File.exist? cachefile then
# move file to package server
binary_pkg_file_path_list.each do |l|
if test_flag then
- FileUtils.ln( l, "#{distribution.location}/temp/#{File.basename(l)}", :force => true )
+ #FileUtils.ln( l, "#{distribution.location}/temp/#{File.basename(l)}", :force => true )
+ if not FileUtil.safeLink( l, "#{distribution.location}/temp/#{File.basename(l)}") then
+ @log.error("Failed to link file [#{l}] to [#{distribution.location}/temp/#{File.basename(l)}]")
+ end
else
- FileUtils.ln( l, "#{distribution.location}/binary/#{File.basename(l)}", :force => true )
+ #FileUtils.ln( l, "#{distribution.location}/binary/#{File.basename(l)}", :force => true )
+ if not FileUtil.safeLink( l, "#{distribution.location}/binary/#{File.basename(l)}") then
+ @log.error("Failed to link file [#{l}] to [#{distribution.location}/binary/#{File.basename(l)}]")
+ end
end
end
if test_flag then
src_file = File.join(distribution.location, l[0])
dest_file = File.join(distribution.location, "temp", l[1])
- FileUtils.ln( src_file, dest_file, :force => true )
+ #FileUtils.ln( src_file, dest_file, :force => true )
+ if not FileUtil.safeLink( src_file, dest_file) then
+ @log.error("Failed to link file [#{src_file}] to [#{dest_file}]")
+ end
else
src_file = File.join(distribution.location, l[0])
dest_file = File.join(distribution.location, "binary", l[1])
- FileUtils.ln( src_file, dest_file, :force => true )
+ #FileUtils.ln( src_file, dest_file, :force => true )
+ if not FileUtil.safeLink( src_file, dest_file) then
+ @log.error("Failed to link file [#{src_file}] to [#{dest_file}]")
+ end
end
end