add 克隆检测

This commit is contained in:
xxq250 2025-06-19 14:10:16 +08:00
parent 14350f6812
commit 76545cf72f
2 changed files with 19 additions and 0 deletions

View File

@ -383,6 +383,24 @@ class ProjectsController < ApplicationController
end
end
def clone_detection
forge_url = "#{Rails.application.config_for(:configuration)['platform_url']}"
target_dir = "2-#{SecureRandom.hex(6)}"
source_url = "#{forge_url}/#{@project.owner.name}/#{@project.identifier}.git"
source_dir = "#{@project.id}-#{SecureRandom.hex(6)}"
clone_dir = File.join(Rails.root, "public", "clone_detection")
system("cd #{clone_dir} && git clone #{params[:target_url]} #{target_dir}")
system("cd #{clone_dir} && git clone #{source_url} #{source_dir}")
system("cd /var/www/NiCad-6.2 && ./nicad6cross functions java /var/www/forgeplus/public/clone_detection/#{source_dir} /var/www/forgeplus/public/clone_detection/#{target_dir}")
view_url = "#{forge_url}/#{source_dir}_functions-blind-crossclones/#{source_dir}_functions-blind-crossclones-0.30-classes-withsource.html"
system("rm -rf /var/www/forgeplus/public/clone_detection/#{source_dir}")
system("rm -rf /var/www/forgeplus/public/clone_detection/#{target_dir}")
render_ok({ view_url: view_url })
rescue
Rails.logger.info("clone_detection...............error#{forge_url},#{source_url}")
system("rm -rf /var/www/forgeplus/public/clone_detection/#{source_dir}")
system("rm -rf /var/www/forgeplus/public/clone_detection/#{target_dir}")
end
private

View File

@ -548,6 +548,7 @@ Rails.application.routes.draw do
get :forks, to: 'projects#fork_users'
match :about, :via => [:get, :put, :post]
post :quit
post :clone_detection
end
end