2018-10-04 16:02:42 +02:00
|
|
|
#!/usr/bin/env python
|
2019-07-12 08:46:20 +02:00
|
|
|
from __future__ import (absolute_import, division, print_function)
|
|
|
|
__metaclass__ = type
|
2018-10-04 16:02:42 +02:00
|
|
|
|
|
|
|
import os
|
2019-08-24 03:08:21 +02:00
|
|
|
import sys
|
2018-10-04 16:02:42 +02:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
2019-08-24 08:40:45 +02:00
|
|
|
root_dir = os.getcwd() + os.path.sep
|
|
|
|
|
2019-08-24 03:08:21 +02:00
|
|
|
for path in sys.argv[1:] or sys.stdin.read().splitlines():
|
|
|
|
if not os.path.islink(path.rstrip(os.path.sep)):
|
|
|
|
continue
|
2018-10-04 16:02:42 +02:00
|
|
|
|
2019-08-24 03:08:21 +02:00
|
|
|
if not os.path.exists(path):
|
|
|
|
print('%s: broken symlinks are not allowed' % path)
|
2019-08-24 08:40:45 +02:00
|
|
|
continue
|
2018-10-04 16:02:42 +02:00
|
|
|
|
2019-08-24 03:08:21 +02:00
|
|
|
if path.endswith(os.path.sep):
|
|
|
|
print('%s: symlinks to directories are not allowed' % path)
|
2019-08-24 08:40:45 +02:00
|
|
|
continue
|
|
|
|
|
|
|
|
real_path = os.path.realpath(path)
|
|
|
|
|
|
|
|
if not real_path.startswith(root_dir):
|
|
|
|
print('%s: symlinks outside content tree are not allowed: %s' % (path, os.path.relpath(real_path, os.path.dirname(path))))
|
|
|
|
continue
|
2018-10-04 16:02:42 +02:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|