Repository: yt-dlp
Issue: "[Errno 18] Invalid cross-device link" when temporary path is on a different filesystem in WSL
Labels: external issue

### DO NOT REMOVE OR SKIP THE ISSUE TEMPLATE

- [X] I understand that I will be **blocked** if I *intentionally* remove or skip any mandatory\* field

### Checklist

- [X] I'm reporting a bug unrelated to a specific site
- [X] I've verified that I'm running yt-dlp version **2023.07.06** ([update instructions](https://github.com/yt-dlp/yt-dlp#update)) or later (specify commit)
- [X] I've checked that all provided URLs are playable in a browser with the same IP and same login details
- [X] I've checked that all URLs and arguments with special characters are [properly quoted or escaped](https://github.com/yt-dlp/yt-dlp/wiki/FAQ#video-url-contains-an-ampersand--and-im-getting-some-strange-output-1-2839-or-v-is-not-recognized-as-an-internal-or-external-command)
- [X] I've searched [known issues](https://github.com/yt-dlp/yt-dlp/issues/3766) and the [bugtracker](https://github.com/yt-dlp/yt-dlp/issues?q=) for similar issues **including closed ones**. DO NOT post duplicates
- [X] I've read the [guidelines for opening an issue](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#opening-an-issue)

### Provide a description that is worded well enough to be understood

Hi!

I have a WSL1 instance connected to an SMB server. The SMB server is the `X:` drive on Windows, and then mounted to `/mnt/x` via `sudo mount -t drvfs X: /mnt/x`.

Running the following command in a WSL1 terminal:

```bash
yt-dlp -vU \
        --paths "home:/mnt/x/yt-dlp" \
        --paths "temp:/tmp/yt-dlp" \
        "https://www.youtube.com/watch?v=BaW_jenozKc"
```

produces the mentioned error when moving the file from temp to home. The file is successfully copied to home, but it never gets deleted from temp.

### Provide verbose output that clearly demonstrates the problem

- [X] Run **your** yt-dlp command with **-vU** flag added (`yt-dlp -vU <your command line>`)
- [ ] If using API, add `'verbose': True` to `YoutubeDL` params instead
- [X] Copy the WHOLE output (starting with `[debug] Command-line config`) and insert it below

### Complete Verbose Output

```shell
[debug] Command-line config: ['-vU', '--paths', 'home:/mnt/x/yt-dlp', '--paths', 'temp:/tmp/yt-dlp', 'https://www.youtube.com/watch?v=BaW_jenozKc']
[debug] Encodings: locale UTF-8, fs utf-8, pref UTF-8, out utf-8 (No ANSI), error utf-8 (No ANSI), screen utf-8 (No ANSI)
[debug] yt-dlp version stable@2023.07.06 [b532a3481] (zip)
[debug] Python 3.11.2 (CPython x86_64 64bit) - Linux-4.4.0-19041-Microsoft-x86_64-with-glibc2.36 (OpenSSL 3.0.9 30 May 2023, glibc 2.36)
[debug] exe versions: ffmpeg 6.0-static (setts), ffprobe 6.0-static
[debug] Optional libraries: mutagen-1.46.0, sqlite3-2.6.0
[debug] Proxy map: {}
[debug] Loaded 1855 extractors
[debug] Fetching release info: https://api.github.com/repos/yt-dlp/yt-dlp/releases/latest
Available version: stable@2023.07.06, Current version: stable@2023.07.06
Current Build Hash: cedf44a9cf3c241520a692c1006d276e6f434d4d945727c47cb1a70d32953f4a
yt-dlp is up to date (stable@2023.07.06)
[youtube] Extracting URL: https://www.youtube.com/watch?v=BaW_jenozKc
[youtube] BaW_jenozKc: Downloading webpage
WARNING: [youtube] unable to extract initial player response; please report this issue on  https://github.com/yt-dlp/yt-dlp/issues?q= , filling out the appropriate issue template. Confirm you are on the latest version using  yt-dlp -U
[youtube] BaW_jenozKc: Downloading ios player API JSON
[youtube] BaW_jenozKc: Downloading android player API JSON
[youtube] BaW_jenozKc: Downloading iframe API JS
[youtube] BaW_jenozKc: Downloading player 7ee36b0e
[youtube] BaW_jenozKc: Downloading web player API JSON
[youtube] BaW_jenozKc: Downloading m3u8 information
WARNING: [youtube] unable to extract yt initial data; please report this issue on  https://github.com/yt-dlp/yt-dlp/issues?q= , filling out the appropriate issue template. Confirm you are on the latest version using  yt-dlp -U
WARNING: [youtube] Incomplete data received in embedded initial data; re-fetching using API.
[youtube] BaW_jenozKc: Downloading initial data API JSON
[debug] Sort order given by extractor: quality, res, fps, hdr:12, source, vcodec:vp9.2, channels, acodec, lang, proto
[debug] Formats sorted by: hasvid, ie_pref, quality, res, fps, hdr:12(7), source, vcodec:vp9.2(10), channels, acodec, lang, proto, size, br, asr, vext, aext, hasaud, id
[debug] Default format spec: bestvideo*+bestaudio/best
[info] BaW_jenozKc: Downloading 1 format(s): 248+251
[debug] Invoking http downloader on "https://rr5---sn-2gb7sn7y.googlevideo.com/videoplayback?expire=1694530799&ei=jygAZePACOy06dsP2qujiAE&ip=2a0c%3A8b40%3A120%3A0%3A304f%3A4f63%3A2f8a%3Ae7e5&id=o-AEScU30gbvFYfKer9oaJgSrbYjMalle2yVjEsx8mkBn2&itag=248&source=youtube&requiressl=yes&mh=Rf&mm=31%2C26&mn=sn-2gb7sn7y%2Csn-c0q7lns7&ms=au%2Conr&mv=m&mvi=5&pl=29&initcwndbps=898750&vprv=1&svpuc=1&mime=video%2Fwebm&gir=yes&clen=988479&dur=9.833&lmt=1544741703689523&mt=1694508807&fvip=4&keepalive=yes&fexp=24007246%2C24363393&c=IOS&txp=5432432&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cvprv%2Csvpuc%2Cmime%2Cgir%2Cclen%2Cdur%2Clmt&sig=AOq0QJ8wRgIhAOQfy-arFAP4sVjxITYkc6oRAerhyHJGcSlZJlAH_RxfAiEAnZyuw00oVJDFNK30MX-Ehb9kEC_Q0d33AeVyhEMuhMU%3D&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AG3C_xAwRQIgAImgMjFISfi-qGjSO-M2O29CWeWz97WJ_qAhBrJRp6cCIQDfvfWA_TckI9QbhUQMNvvczh8geL3dAYAz3GKgMKJ2yQ%3D%3D"
[download] Destination: /tmp/yt-dlp/youtube-dl test video ＂'⧸⧹ä↭𝕐 [BaW_jenozKc].f248.webm

[download]   0.1% of  965.31KiB at  333.68KiB/s ETA 00:02
[download]   0.3% of  965.31KiB at  927.05KiB/s ETA 00:01
[download]   0.7% of  965.31KiB at    1.98MiB/s ETA 00:00
[download]   1.6% of  965.31KiB at    4.07MiB/s ETA 00:00
[download]   3.2% of  965.31KiB at    2.20MiB/s ETA 00:00
[download]   6.5% of  965.31KiB at    2.27MiB/s ETA 00:00
[download]  13.2% of  965.31KiB at    3.60MiB/s ETA 00:00
[download]  26.4% of  965.31KiB at    5.33MiB/s ETA 00:00
[download]  52.9% of  965.31KiB at    8.57MiB/s ETA 00:00
[download] 100.0% of  965.31KiB at   12.00MiB/s ETA 00:00
[download] 100% of  965.31KiB in 00:00:00 at 7.98MiB/s   
[debug] Invoking http downloader on "https://rr5---sn-2gb7sn7y.googlevideo.com/videoplayback?expire=1694530799&ei=jygAZcbiJouCgQfBk67gAQ&ip=2a0c%3A8b40%3A120%3A0%3A304f%3A4f63%3A2f8a%3Ae7e5&id=o-ALSBS5JhVJjzgiUL3M1SRS0oqsLF9TPQHE2N4pkA-lrm&itag=251&source=youtube&requiressl=yes&mh=Rf&mm=31%2C26&mn=sn-2gb7sn7y%2Csn-c0q7lns7&ms=au%2Conr&mv=m&mvi=5&pl=29&initcwndbps=1226250&spc=UWF9f2mhCL3YCUyt3ZkTtqi1lCgxgbg&vprv=1&svpuc=1&mime=audio%2Fwebm&gir=yes&clen=142292&dur=9.841&lmt=1506055557712479&mt=1694509028&fvip=4&keepalive=yes&fexp=24007246%2C51000022&beids=24350017&c=ANDROID&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cspc%2Cvprv%2Csvpuc%2Cmime%2Cgir%2Cclen%2Cdur%2Clmt&sig=AOq0QJ8wRgIhAMHHDeszkIw8nwGeYNLt59C85vGkl-IRuAoHJAPFj9JcAiEAgdzTKCHibk6K14PMB5SFdA3gckytO7K1oqzAg9tajSU%3D&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AG3C_xAwRgIhANwFCH1yDwtT0wfEj1CJnYxSOCocojMfdw6VCTLqDI-YAiEA6eYGFH3ynFI7StSSKVu3Hs5ni6ieHeEAzRjMy-4dMZQ%3D"
[download] Destination: /tmp/yt-dlp/youtube-dl test video ＂'⧸⧹ä↭𝕐 [BaW_jenozKc].f251.webm

[download]   0.7% of  138.96KiB at  316.74KiB/s ETA 00:00
[download]   2.2% of  138.96KiB at  888.87KiB/s ETA 00:00
[download]   5.0% of  138.96KiB at    1.92MiB/s ETA 00:00
[download]  10.8% of  138.96KiB at    3.93MiB/s ETA 00:00
[download]  22.3% of  138.96KiB at    3.02MiB/s ETA 00:00
[download]  45.3% of  138.96KiB at    4.02MiB/s ETA 00:00
[download]  91.4% of  138.96KiB at    5.11MiB/s ETA 00:00
[download] 100.0% of  138.96KiB at    5.36MiB/s ETA 00:00
[download] 100% of  138.96KiB in 00:00:00 at 2.02MiB/s   
[Merger] Merging formats into "/tmp/yt-dlp/youtube-dl test video ＂'⧸⧹ä↭𝕐 [BaW_jenozKc].webm"
[debug] ffmpeg command line: ffmpeg -y -loglevel repeat+info -i 'file:/tmp/yt-dlp/youtube-dl test video ＂'"'"'⧸⧹ä↭𝕐 [BaW_jenozKc].f248.webm' -i 'file:/tmp/yt-dlp/youtube-dl test video ＂'"'"'⧸⧹ä↭𝕐 [BaW_jenozKc].f251.webm' -c copy -map 0:v:0 -map 1:a:0 -movflags +faststart 'file:/tmp/yt-dlp/youtube-dl test video ＂'"'"'⧸⧹ä↭𝕐 [BaW_jenozKc].temp.webm'
Deleting original file /tmp/yt-dlp/youtube-dl test video ＂'⧸⧹ä↭𝕐 [BaW_jenozKc].f248.webm (pass -k to keep)
Deleting original file /tmp/yt-dlp/youtube-dl test video ＂'⧸⧹ä↭𝕐 [BaW_jenozKc].f251.webm (pass -k to keep)
[MoveFiles] Moving file "/tmp/yt-dlp/youtube-dl test video ＂'⧸⧹ä↭𝕐 [BaW_jenozKc].webm" to "/mnt/x/yt-dlp/youtube-dl test video ＂'⧸⧹ä↭𝕐 [BaW_jenozKc].webm"
ERROR: [Errno 1] Operation not permitted
Traceback (most recent call last):
  File "/usr/lib/python3.11/shutil.py", line 825, in move
    os.rename(src, real_dst)
OSError: [Errno 18] Invalid cross-device link: "/tmp/yt-dlp/youtube-dl test video ＂'⧸⧹ä↭𝕐 [BaW_jenozKc].webm" -> "/mnt/x/yt-dlp/youtube-dl test video ＂'⧸⧹ä↭𝕐 [BaW_jenozKc].webm"

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/chylex/.local/bin/yt-dlp/yt_dlp/YoutubeDL.py", line 1560, in wrapper
    return func(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/chylex/.local/bin/yt-dlp/yt_dlp/YoutubeDL.py", line 1709, in __extract_info
    return self.process_ie_result(ie_result, download, extra_info)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/chylex/.local/bin/yt-dlp/yt_dlp/YoutubeDL.py", line 1768, in process_ie_result
    ie_result = self.process_video_result(ie_result, download=download)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/chylex/.local/bin/yt-dlp/yt_dlp/YoutubeDL.py", line 2897, in process_video_result
    self.process_info(new_info)
  File "/home/chylex/.local/bin/yt-dlp/yt_dlp/YoutubeDL.py", line 3439, in process_info
    replace_info_dict(self.post_process(dl_filename, info_dict, files_to_move))
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/chylex/.local/bin/yt-dlp/yt_dlp/YoutubeDL.py", line 3622, in post_process
    info = self.run_pp(MoveFilesAfterDownloadPP(self), info)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/chylex/.local/bin/yt-dlp/yt_dlp/YoutubeDL.py", line 3581, in run_pp
    files_to_delete, infodict = pp.run(infodict)
                                ^^^^^^^^^^^^^^^^
  File "/home/chylex/.local/bin/yt-dlp/yt_dlp/postprocessor/common.py", line 24, in run
    ret = func(self, info, *args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/chylex/.local/bin/yt-dlp/yt_dlp/postprocessor/movefilesafterdownload.py", line 50, in run
    shutil.move(oldfile, newfile)  # os.rename cannot move between volumes
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/shutil.py", line 845, in move
    copy_function(src, real_dst)
  File "/usr/lib/python3.11/shutil.py", line 437, in copy2
    copystat(src, dst, follow_symlinks=follow_symlinks)
  File "/usr/lib/python3.11/shutil.py", line 376, in copystat
    lookup("utime")(dst, ns=(st.st_atime_ns, st.st_mtime_ns),
PermissionError: [Errno 1] Operation not permitted
```