mirror of
https://github.com/servo/servo.git
synced 2025-06-19 22:59:03 +01:00
Improve clean-cargo-cache
This commit is contained in:
parent
3c267d7fdd
commit
0e072df8c3
1 changed files with 20 additions and 19 deletions
|
@ -384,6 +384,8 @@ class MachCommands(CommandBase):
|
||||||
cargo_dir = os.environ.get("CARGO_HOME")
|
cargo_dir = os.environ.get("CARGO_HOME")
|
||||||
else:
|
else:
|
||||||
cargo_dir = path.join(self.context.topdir, ".cargo")
|
cargo_dir = path.join(self.context.topdir, ".cargo")
|
||||||
|
if not os.path.isdir(cargo_dir):
|
||||||
|
return
|
||||||
cargo_file = open(path.join(self.context.topdir, "Cargo.lock"))
|
cargo_file = open(path.join(self.context.topdir, "Cargo.lock"))
|
||||||
content = toml.load(cargo_file)
|
content = toml.load(cargo_file)
|
||||||
|
|
||||||
|
@ -438,12 +440,17 @@ class MachCommands(CommandBase):
|
||||||
"exist": [],
|
"exist": [],
|
||||||
}
|
}
|
||||||
if os.path.isdir(path.join(git_checkout_dir, d)):
|
if os.path.isdir(path.join(git_checkout_dir, d)):
|
||||||
for d2 in os.listdir(path.join(git_checkout_dir, d)):
|
with cd(path.join(git_checkout_dir, d)):
|
||||||
|
git_crate_hash = glob.glob('*')
|
||||||
|
if not git_crate_hash or not os.path.isdir(path.join(git_db_dir, d)):
|
||||||
|
packages["git"][crate_name]["exist"].append(("del", d, ""))
|
||||||
|
continue
|
||||||
|
for d2 in git_crate_hash:
|
||||||
dep_path = path.join(git_checkout_dir, d, d2)
|
dep_path = path.join(git_checkout_dir, d, d2)
|
||||||
if os.path.isdir(dep_path):
|
if os.path.isdir(dep_path):
|
||||||
packages["git"][crate_name]["exist"].append((path.getmtime(dep_path), d, d2))
|
packages["git"][crate_name]["exist"].append((path.getmtime(dep_path), d, d2))
|
||||||
elif os.path.isdir(path.join(git_db_dir, d)):
|
elif os.path.isdir(path.join(git_db_dir, d)):
|
||||||
packages["git"][crate_name]["exist"].append(("db", d, ""))
|
packages["git"][crate_name]["exist"].append(("del", d, ""))
|
||||||
|
|
||||||
for d in os.listdir(crates_src_dir):
|
for d in os.listdir(crates_src_dir):
|
||||||
crate_name = re.sub(r"\-\d+(\.\d+){1,3}.+", "", d)
|
crate_name = re.sub(r"\-\d+(\.\d+){1,3}.+", "", d)
|
||||||
|
@ -463,36 +470,30 @@ class MachCommands(CommandBase):
|
||||||
for exist in sorted(existed_crates, reverse=True):
|
for exist in sorted(existed_crates, reverse=True):
|
||||||
current_crate = packages[packages_type][crate_name]["current"]
|
current_crate = packages[packages_type][crate_name]["current"]
|
||||||
size = 0
|
size = 0
|
||||||
exist_name = exist
|
exist_name = path.join(exist[1], exist[2]) if packages_type == "git" else exist
|
||||||
exist_item = exist[2] if packages_type == "git" else exist
|
exist_item = exist[2] if packages_type == "git" else exist
|
||||||
if exist_item not in current_crate:
|
if exist_item not in current_crate:
|
||||||
crate_count += 1
|
crate_count += 1
|
||||||
|
if int(crate_count) >= int(keep) or not current_crate or \
|
||||||
|
exist[0] == "del" or exist[2] == "master":
|
||||||
removing_anything = True
|
removing_anything = True
|
||||||
if int(crate_count) >= int(keep) or not current_crate:
|
|
||||||
crate_paths = []
|
crate_paths = []
|
||||||
if packages_type == "git":
|
if packages_type == "git":
|
||||||
exist_checkout_path = path.join(git_checkout_dir, exist[1])
|
exist_checkout_path = path.join(git_checkout_dir, exist[1])
|
||||||
exist_db_path = path.join(git_db_dir, exist[1])
|
exist_db_path = path.join(git_db_dir, exist[1])
|
||||||
exist_name = path.join(exist[1], exist[2])
|
|
||||||
exist_path = path.join(git_checkout_dir, exist_name)
|
exist_path = path.join(git_checkout_dir, exist_name)
|
||||||
|
|
||||||
if exist[0] == "db":
|
if exist[0] == "del":
|
||||||
|
if os.path.isdir(exist_checkout_path):
|
||||||
|
crate_paths.append(exist_checkout_path)
|
||||||
|
if os.path.isdir(exist_db_path):
|
||||||
crate_paths.append(exist_db_path)
|
crate_paths.append(exist_db_path)
|
||||||
crate_count += -1
|
crate_count += -1
|
||||||
else:
|
else:
|
||||||
crate_paths.append(exist_path)
|
crate_paths.append(exist_path)
|
||||||
|
|
||||||
# remove crate from checkout if doesn't exist in db directory
|
exist_checkout_list = glob.glob(path.join(exist_checkout_path, '*'))
|
||||||
if not os.path.isdir(exist_db_path):
|
if len(exist_checkout_list) <= 1:
|
||||||
crate_count += -1
|
|
||||||
|
|
||||||
with cd(path.join(exist_path, ".git", "objects", "pack")):
|
|
||||||
for pack in glob.glob("*"):
|
|
||||||
pack_path = path.join(exist_db_path, "objects", "pack", pack)
|
|
||||||
if os.path.exists(pack_path):
|
|
||||||
crate_paths.append(pack_path)
|
|
||||||
|
|
||||||
if len(os.listdir(exist_checkout_path)) <= 1:
|
|
||||||
crate_paths.append(exist_checkout_path)
|
crate_paths.append(exist_checkout_path)
|
||||||
if os.path.isdir(exist_db_path):
|
if os.path.isdir(exist_db_path):
|
||||||
crate_paths.append(exist_db_path)
|
crate_paths.append(exist_db_path)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue