# R&D - What will happen if Cli broke in the middle ? ## How to break - Quit signal, for example `ctrl+c` - Panics, if it happens while executing something through cli ## Related problem - Multiple user trying to install the same package at the same time. ## How currently works - At the beginning the package information related to its name and version are stored - Then the installation block is executed - After installation is completed, the package is stored in `install database` - Same for remove, gets removed then stored at `removed database` ## Scenarios ### 1 : exits before installing - there will not be any issues ### 2 : exits during installation - for apt installs - there will be no issues,as apt can install same package multiple times - so if while installing cli breaks, it will not be installed in the system and will not be stored in database - others - may be problematic - need to check in details ### 3 : exits after installation but before storing to db - for apt installs - even though the system has package installed, theres no record of it in the databse - again trying to install there will be no issues,as apt can install same package multiple times, and the database has no entry - others - may be problematic - need to check in details ## How to solve ? - Through help of database and another process - when executing each stage we can assign state of that installation - Before install status : install starting - after install status : install completed - after db entry : added to db - .... - pros - we can track exactly where the program exited, and take decisions based on that - cons - easy solutin but complex logic will arise, for example a lot of conditionals on installation, such as check state of the package, if package in certain state, do this and so on. - need another process that will check the state of package, if installed and not in database, it will push to `install database` same for the remove - Using graceful shutdown - the idea is to detect the exit signal , but rather than terminating instantly, wait for the installation to complete and then exit program - pros - it will make sure that everything goes right - cons - for panics it will not work - the user might want to exit instantly but rather he will have to wait, violating the purpose of the user - Using Database and CLI - Database stores states of each installation - We can track at what level the installation is - started - completed - Fetch pending installs, or the broken ones - Run cleanup - Remove everything of that package - Now we can fresh install