systemd / mkosi

💽 Build Bespoke OS Images
https://mkosi.systemd.io/
1.18k stars 319 forks source link

Source copying is borked when there are modified symlinks #142

Closed fsateler closed 7 years ago

fsateler commented 7 years ago

May be related to #123? Steps to reproduce:

% git clone https://github.com/systemd/systemd.git
% cd systemd
% ln -sf .mkosi/mkosi.debian mkosi.default
% sudo mkosi
# snip lots of output
‣ Copying in build script and sources...
Cloning into '/var/tmp/mkosi-3nz7dw74/root/root/src'...
warning: --depth is ignored in local clones; use file:// instead.
done.
‣ Unmounting Package Cache...
‣ Unmounting Package Cache complete.
‣ Unmounting image...
‣ Unmounting image complete.
‣ Detaching image file...
‣ Detaching image file complete.
Traceback (most recent call last):
  File "/usr/bin/mkosi", line 2904, in <module>
    main()
  File "/usr/bin/mkosi", line 2900, in main
    build_stuff(args)
  File "/usr/bin/mkosi", line 2846, in build_stuff
    raw, tar, root_hash = build_image(args, workspace, run_build_script=True)
  File "/usr/bin/mkosi", line 2706, in build_image
    install_build_src(args, workspace.name, run_build_script, for_cache)
  File "/usr/bin/mkosi", line 1361, in install_build_src
    copy_git_files(args.build_sources, target, git_files=args.git_files)
  File "/usr/bin/mkosi", line 1339, in copy_git_files
    shutil.copy2(src_path, dest_path, follow_symlinks=False)
  File "/usr/lib/python3.5/shutil.py", line 257, in copy2
    copyfile(src, dst, follow_symlinks=follow_symlinks)
  File "/usr/lib/python3.5/shutil.py", line 118, in copyfile
    os.symlink(os.readlink(src), dst)
FileExistsError: [Errno 17] File exists: '.mkosi/mkosi.debian' -> '/var/tmp/mkosi-3nz7dw74/root/root/src/mkosi.default'

cc @lucasdemarchi

lucasdemarchi commented 7 years ago

Humn... yeah, sorry about that, it seems I broke it. I'll take a look on how to fix it.

TrumanLing commented 7 years ago

Same problem +1

TrumanLing commented 7 years ago

@fsateler @lucasdemarchi @poettering can we check whether file is symbolic link? if yes, delete it then copy it.

lucasdemarchi commented 7 years ago

@TrumanLing what I was thinking but never got to implement (sorry, my bad) was to have a try/catch and use a force flag on the symlink creation.