Cannot Upgrade System

No, i did. :sweat_smile:
[baris@Samanyolu ~]$ sudo mkdir /var/lib/pacman/OLD

[sudo] password for baris: 
mkdir: cannot create directory ‘/var/lib/pacman/OLD’: File exists

Of course, sorry I had a brainfart and forgot to check the error message again before posting.

ls /var/lib/pacman/OLD | grep breath
ls /var/lib/pacman/local | grep breath
[baris@Samanyolu ~]$ ls /var/lib/pacman/local | grep breathe
[baris@Samanyolu ~]$ ls /var/lib/pacman/OLD | grep breath
breath2-icon-themes-1.0.10-3
breath2-icon-themes-1.0.11-1
breath2-wallpaper-1.0.10-2
breath2-wallpaper-1.0.11-1

Ok, I was right the first time, seems to be a bug with checking the path.

I tested on my machine, luckily I had a few dups, this seems to work. :crossed_fingers:

#!/usr/bin/env python

import os,re, datetime, pathlib

d = '/var/lib/pacman/local'

packages = os.listdir(d)
packages.sort()

pkgname_search = re.compile('^(.*?)-[0-9]')

old_packages = []

for pkg1 in packages:
	# print(pkg1)
	if pkg1 in old_packages or pkg1 == 'ALPM_DB_VERSION':
		continue
		
	#get package name
	pkgname = pkgname_search.findall(pkg1)[0]
	
	#look for other items with the same package name
	for pkg2 in packages:
		# print(pkg2)
		if pkg2 == pkg1 or pkg2 == 'ALPM_DB_VERSION':
			continue
		if pkg2 in old_packages:
			continue
		if pkgname == pkgname_search.findall(pkg2)[0]:
			# We now have two duplicate packages, we want to delete the old one
			
			old_package = pkg1
			path1 = os.path.join(d,pkg1)
			path2 = os.path.join(d,pkg2)
			if os.stat(path1).st_mtime > os.stat(path2).st_mtime:
				old_package = pkg2
			
			old_packages.append(old_package)
			#print ('duplicate found:\t')
			#print (pkg1)
			#print (pkg2)
			#print ('old:', old_package)
			
			oldpath = os.path.join(d,old_package)
			target = os.path.join('/var/lib/pacman/OLD',old_package)
			cmd = 'mv "%s" "%s"' % (oldpath, target)
			opath = pathlib.Path(oldpath)
			#double-check that the oldpath still exists (it may have been removed in a previous pass)
			# if os.path.exists(oldpath):
			if opath.exists():
				print(cmd)
				os.system(cmd)

EDIT:
Better scripts in posts 43 and 44.

Warning: Could not start program '/home/baris/rmDuplicate.sh' with arguments '/home/baris/rmDuplicate.sh'.



Warning: execve: Exec format error

Sorry missed the shebang #!/usr/bin/env python, fixed it.

1 Like

It seems to be working but it’s been 24 min. Is this normal?` :sweat_smile:
My HDD working by the way because it is roaring :sweat_smile:

It would depend on how many files etc, but it only takes a 1-2 mins at most for me but I’m on SSD. :man_shrugging:

I’ve been looking at it more closely the script doesn’t handle a couple of edge cases well. Just means a few files may be moved when they shouldn’t be. Such as kicad-library-3d.

Might take a while, but I’m working on it.

EDIT:

For those who don’t have pamac installed (not many), here’s a modified version of the below script that uses the pacman database. It lists the dups and asks if you want to remove them.

Script
#!/usr/bin/python

import pathlib, subprocess, shlex
from pyalpm import Handle

def list_installed_pkgs():
    pkgs = localdb.search("")
    for pkg in pkgs:
        yield f"{pkg.name}-{pkg.version}"


handle = Handle(".", "/var/lib/pacman")
localdb = handle.get_localdb()

pkgs = list(list_installed_pkgs())

p = pathlib.Path('/var/lib/pacman/local')
dirs = p.glob("*")

dup_pkgs = []
for pkg in dirs:
    if pkg.name not in pkgs:
        if pkg.name != 'ALPM_DB_VERSION':
            dup_pkgs.append(pkg)
            print(f"'{pkg.name}'")

if len(dup_pkgs) > 0:
    ans = input("\nDo you want to delete these files? y/N  ")
    if ans and ans[0].lower() == "y":
        for pkg in dup_pkgs:
            subprocess.run(shlex.split(f"sudo rm -r {pkg}"))
1 Like

other version ?

#!/usr/bin/python

import os
import gi
gi.require_version('Pamac', '11')
from gi.repository import Pamac

def list_installed_pkgs():
    pkgs = db.get_installed_pkgs()
    for pkg in pkgs:
        yield f"{pkg.get_name()}-{pkg.get_version()}"


config = Pamac.Config(conf_path="/etc/pamac.conf")
db = Pamac.Database(config=config)
pkgs = list(list_installed_pkgs())

print("rm -rf # list:")
dirs = os.listdir('/var/lib/pacman/local')
for pkg in dirs:
    if pkg not in pkgs:
        # print(pkg)
        if pkg != 'ALPM_DB_VERSION':
            print(f"'/var/lib/pacman/local/{pkg}' ", end='')

with pamac we have package list with “last” version, and if directory not in list, we can remove

here, script less than 1 minute as run “rm” command

2 Likes

please not use screen copy by use text copy/paste :wink:

1 Like

I didn’t understand. Ah, no i mean when i ran the script, terminal looked like this.

@Baris so…?? What is the outcome?? :slight_smile: Did you manage to fix the issue ??
If so read the announcements for stable update before you do it, so you don’t end up with another problem.

Script did nothing. :pleading_face: As seen in the picture, Konsole just didn’t do anything.

Have you tried updating since? :slight_smile:

Yeah, same error.

Hmm… If @dmt’s script didn’t help then you try manually. Leave only one package version ( latest ) of each pkg.
Also ALPM_DB_VERSION just delete it from the file and see what happens.

When you finish deleting the packages from the file, remove the databases and than try to repopulate.
Pacman should read your /var/lib/pacman/local file and make new databeses from that.

Edit Run every thing with root privilege

I will try manually tomorrow. :+1:t4:

Instead of manually deleting, I reinstalled Manjaro and now there’s no problem. :+1:t3:

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.