Debian package files are removed when reinstall them

303 Views Asked by At

recently, I've been building my project for debian package.

I've made my_project.deb and it is installed well.

But, when I reinstall it, it doesn't work well.

$ sudo dpkg -i my_project_1.0.0.deb
...
Preparing to unpack my_project.deb ...
Unpacking my_project (1.0.0) ...
Setting up my_project (1.0.0) ...
# install success
$ ls /usr/share/my_proejct # run successfully

$ sudo dpkg -i my_project_1.0.1.deb
Preparing to unpack my_project.deb ...
Unpacking my_project (1.0.1) ...
Setting up my_project (1.0.1) ...
# install failed
$ ls /usr/share/my_proejct # No such file or directory

To find out where my project's files are gone, I wrote maintainer scripts(preinst, postinst, prerm, postrm) and ls files like below.

$ cat preinst
echo "I'm preinst
ls /usr/share/my_project
echo "bye preinst"

Then,

$ sudo dpkg -i my_project_1.0.0.deb
# install success
$ sudo dpkg -i my_project_1.0.0.deb
Preparing to unpack my_project_1.0.0.deb ...
I'm prerm
bin  doc  lib # ls output
bye prerm
I'm preinst
doc  lib # ls output. `bin` is removed. Why..?
bye preinst
Unpacking my_project (1.0.0) over (1.0.0) ...
I'm postrm
bin  doc  lib # ls output. Seems they are unpacked well
bye postrm
Setting up my_project (1.0.0) ...
I'm postinst
ls: cannot access '/usr/share/my_project/': No such file or directory # ls output. They are removed. Why..
bye postinst

Is there anything wrong I did? I can't the reason why these happened.

1

There are 1 best solutions below

0
On

Turns out, it is my fault.

When upgrading the package, here's the steps of it.

  • old.prerm upgrade
  • new.preinst upgrade
  • Files are unpacked
  • old.postrm upgrade # here
  • Old files are deleted
  • new.postinst upgrade

My postrm script always removes my_project folder, which causes the unpacked files to be removed. So, I've changed this not to remove the folder when upgrade argument is given to postrm.