From 76545cf72f5581887478633fcc15555a33a0c124 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 19 Jun 2025 14:10:16 +0800 Subject: [PATCH] =?UTF-8?q?add=20=E5=85=8B=E9=9A=86=E6=A3=80=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/projects_controller.rb | 18 ++++++++++++++++++ config/routes.rb | 1 + 2 files changed, 19 insertions(+) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index dfe8cf3b4..261bf1025 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -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 diff --git a/config/routes.rb b/config/routes.rb index 3e9145ae7..086ff5261 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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