aboutsummaryrefslogtreecommitdiff
blob: cf88365ee756592fcedcd9501af61c0b8e403f89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python
# Copyright 1999-2021 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

import errno
import sys
from os import path as osp

if osp.isfile(
    osp.join(osp.dirname(osp.dirname(osp.realpath(__file__))), ".portage_not_installed")
):
    sys.path.insert(
        0, osp.join(osp.dirname(osp.dirname(osp.realpath(__file__))), "lib")
    )
import portage

portage._internal_caller = True

if not sys.argv[1:] or "--help" in sys.argv or "-h" in sys.argv:
    print()
    print("You must specify directories with hardlink-locks to clean.")
    print("You may optionally specify --force, which will remove all")
    print("of the locks, even if we can't establish if they are in use.")
    print("Please attempt cleaning without force first.")
    print()
    print(f"{sys.argv[0]} {portage.settings['DISTDIR']}/.locks")
    print(f"{sys.argv[0]} --force {portage.settings['DISTDIR']}/.locks")
    print()
    sys.exit(1)

force = False
if "--force" in sys.argv[1:]:
    force = True

for x in sys.argv[1:]:
    if x == "--force":
        continue
    try:
        for y in portage.locks.hardlock_cleanup(x, remove_all_locks=force):
            print(y)
        print()

    except OSError as e:
        if e.errno in (errno.ENOENT, errno.ENOTDIR):
            print(f"!!! {x} is not a directory or does not exist")
        else:
            raise
        sys.exit(e.errno)