From d61f1838fc26f0fe2f63445211bb45b557fb99cb Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 5 Jul 2019 09:45:51 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/zip_service.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/services/zip_service.rb b/app/services/zip_service.rb index cb278e98..009fee77 100644 --- a/app/services/zip_service.rb +++ b/app/services/zip_service.rb @@ -314,6 +314,7 @@ module ZipService rename_zipfile = zip_name_refer ||= "#{Time.now.to_i.to_s}.zip" # 文件名过长 + index = 1 if rename_zipfile.size > MAX_PATH rename_zipfile = rename_zipfile[0,rename_zipfile.size-4][0,MAX_PATH-4] + rename_zipfile[-4,4] end @@ -329,7 +330,10 @@ module ZipService begin zipfile.add(rename_file, filename) rescue Exception => e - zipfile.get_output_stream('FILE_NOTICE.txt'){|os| os.write l(:label_file_exist)} + rename_file = rename_same_file(rename_file, index) + index += 1 + zipfile.add(rename_file, filename) + # zipfile.get_output_stream('FILE_NOTICE.txt'){|os| os.write l(:label_file_exist)} next end end @@ -376,4 +380,11 @@ module ZipService attach = Attachment.find_by_disk_filename(name) attach.filename end + + def rename_same_file(name, index) + basename = File.basename(name, ".*") + new_basename = basename + "_" + index.to_s + extname = File.extname(name) + new_basename + extname + end end \ No newline at end of file