Le 21 août 2013 08:04, "Raphael Hertzog" <hert...@debian.org> a écrit : > > Hi, > > On Tue, 20 Aug 2013, Bastien ROUCARIES wrote: > > > A possible way to do this could be: > > > * Move the directory away in preinst (<dir>.dpkg-backup), put in place a symlink > > > pointing to the renamed directory > > ok this is easy > > > * In postinst, move remaining files from the temporary directory to > > > the directory pointed by the symlink (except if there's already a new > > > file at the expected location, in that case warn about the conflict > > > and leave the file). > > > > How can I do this ? mv -n is not portable, and if I use find how to > > handle symlink ? > > mymove() { > local origin=$1 > local target=$2 > while read path; do > # do the work for each file here > done > } Not safe if a filename include a new line...
Find -print0 And replacing read by read -r -d $'\0' is safer but I do not know if it is portable. Or xargs but we need to fork for each file and we get the portability problem of find print0. What do you prefer ? > find $origin | mymove $origin $target > > You can use compute the relative path names by stripping $origin from the > stard and you can do whatever checks you want with "test". > > > Should I check if md5sum are the same in case of conflicts and > > override in this case ? > > I would not override but it's interesting to compare the files > yes. That way we can avoid complaining about a conflict when in fact > both files are identical. And we can silently drop our copy. > > Cheers, > -- > Raphaël Hertzog ◈ Debian Developer > > Discover the Debian Administrator's Handbook: > → http://debian-handbook.info/get/