mirror of
https://github.com/platformio/platformio-core.git
synced 2025-07-30 18:17:13 +02:00
Added script for fixing broken symlinks in toolchains
This commit is contained in:
47
scripts/fixsymlink.py
Normal file
47
scripts/fixsymlink.py
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
# Copyright (C) Ivan Kravets <me@ikravets.com>
|
||||||
|
# See LICENSE for details.
|
||||||
|
|
||||||
|
from os import chdir, getcwd, readlink, remove, symlink, walk
|
||||||
|
from os.path import exists, islink, join, split
|
||||||
|
from sys import exit as sys_exit
|
||||||
|
|
||||||
|
|
||||||
|
def get_symrelpath(root, sympath, ending=None):
|
||||||
|
head, tail = split(sympath)
|
||||||
|
|
||||||
|
if ending:
|
||||||
|
ending = join(tail, ending)
|
||||||
|
relpath = join("..", ending)
|
||||||
|
else:
|
||||||
|
relpath = tail
|
||||||
|
ending = tail
|
||||||
|
|
||||||
|
if exists(join(root, relpath)):
|
||||||
|
return relpath
|
||||||
|
elif head:
|
||||||
|
return get_symrelpath(root, head, ending)
|
||||||
|
else:
|
||||||
|
raise Exception()
|
||||||
|
|
||||||
|
|
||||||
|
def fix_symlink(root, fname, brokenlink):
|
||||||
|
prevcwd = getcwd()
|
||||||
|
symrelpath = get_symrelpath(root, brokenlink)
|
||||||
|
|
||||||
|
chdir(root)
|
||||||
|
remove(fname)
|
||||||
|
symlink(symrelpath, fname)
|
||||||
|
chdir(prevcwd)
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
for root, dirnames, filenames in walk("."):
|
||||||
|
for f in filenames:
|
||||||
|
path = join(root, f)
|
||||||
|
if not islink(path) or exists(path):
|
||||||
|
continue
|
||||||
|
fix_symlink(root, f, readlink(path))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
sys_exit(main())
|
Reference in New Issue
Block a user