patch打补丁试遇到软链接指向文件发生改变

场景

新版本某个文件有版本更新,软链接指向文件发生了改变,制作patch成的补丁文件里面,软链接文件会被制作成内容为指向文件的普通文件,打补丁的时候文件名相同的链接文件和普通文件会有冲突,这时候需要删掉因为冲突产生的"*.rej"文件和软链接文件,再重新建立软链接。

原来文件

[root@localhost ln_test]# ls -l test-old/
total 4
-rw-r--r-- 1 root root  5 Jun 20 14:28 test.1.2.txt
lrwxrwxrwx 1 root root 12 Jun 20 14:31 test.txt -> test.1.2.txt

新文件

[root@localhost ln_test]# ls test1/ -l
total 4
-rw-r--r-- 1 root root 10 Jun 19 16:50 SafeAgent.1.3.jar
lrwxrwxrwx 1 root root 17 Jun 20 14:27 SafeAgent.jar -> SafeAgent.1.3.jar

制作补丁文件

[root@localhost ln_test]# diff -Naur test-old/ test-new/ > test.patch

打补丁(失败)

[root@localhost ln_test]# cd test-old
[root@localhost test-old]# patch -p1 < ../test.patch 
patching file test.1.2.txt
patching file test.1.3.txt
File test.txt is not a regular file -- refusing to patch
1 out of 1 hunk ignored -- saving rejects to file test.txt.rej
[root@localhost test-old]# ls -l
total 8
-rw-r--r-- 1 root root  10 Jun 20 14:34 test.1.3.txt
lrwxrwxrwx 1 root root  12 Jun 20 14:31 test.txt -> test.1.2.txt
-rw-r--r-- 1 root root 124 Jun 20 14:34 test.txt.rej

解决问题:

[root@localhost test-old]# cd ../
[root@localhost ln_test]# ls
test-new  test-old  test.patch  test.sh
[root@localhost ln_test]# ./test.sh 
==== ln -s ././test.1.3.txt test.txt
/data/work/aarch64/ln_test
[root@localhost ln_test]# ls test-old -l
total 4
-rw-r--r-- 1 root root 10 Jun 20 14:34 test.1.3.txt
lrwxrwxrwx 1 root root 16 Jun 20 14:36 test.txt -> ././test.1.3.txt

附上脚本teset.sh

#!/bin/bash

find -name *.rej | while read file
do
	soft_ln=$(echo ${file%.*})
	if [ -L ${soft_ln} ];then
		ln_file_dir=$(echo ${file%/*})
		rm -f ${file}
		
		cd ${ln_file_dir}
		ln_file=$(echo ${soft_ln##*/})
		prefix=$(echo ${ln_file%.*})

		real_file=$(ls -l ${ln_file} | awk '{print $11}')
		rm -f ${ln_file}
		rm -f ${real_file}
		
		if [ -d "$(echo ${ln_file%/*})" ];then
			real_file_dir=$(echo ${file%/*})
		else
			real_file_dir=.
		fi
		
		new_file=$(ls -l "${real_file_dir}/${prefix}"* | awk '{print $9}')
		
		echo "==== ln -s ${real_file_dir}/${new_file} ${ln_file}"
		
		ln -s ${real_file_dir}/${new_file} ${ln_file} 
		cd -
	fi
			
done

如有其他解决办法,欢迎讨论。。。。。。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

酣楼驻海

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值