Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: to_pdf Plugin: Cross-Device File Move Fails with os.Rename #1221

Open
1 task done
wmahfoudh opened this issue Dec 22, 2024 · 1 comment
Open
1 task done

[Bug]: to_pdf Plugin: Cross-Device File Move Fails with os.Rename #1221

wmahfoudh opened this issue Dec 22, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@wmahfoudh
Copy link
Contributor

What happened?

I run to_pdf sample.tex and had this error Error moving output file: rename /tmp/latex_1847002621/input.pdf sample.pdf: invalid cross-device link

The to_pdf plugin fails when attempting to move a generated PDF file across different filesystems using the os.Rename function.

Found out that this issue is triggered because my /tmp folder and the current working directory are mounted on separate filesystems.

Output of the df showing different file systems (using btrfs here):

df /tmp . 
Filesystem      Size  Used Avail Use% Mounted on
tmpfs           7.5G  996K  7.5G   1% /tmp
/dev/nvme0n1p3  1.8T  653G  1.2T  37% /home

Version check

  • Yes I was.

Relevant log output

Environment Details:

    Operating System: Arch Linux
    Plugin Version: to_pdf (latest)
    
FileSystem:

    df /tmp .
    Filesystem      Size  Used Avail Use% Mounted on
    tmpfs           7.5G  996K  7.5G   1% /tmp
    /dev/nvme0n1p3  1.8T  653G  1.2T  37% /home

Relevant screenshots (optional)

No response

@wmahfoudh wmahfoudh added the bug Something isn't working label Dec 22, 2024
@wmahfoudh
Copy link
Contributor Author

Replacing os.Rename with a combination of io.Copy and os.Remove solves the issue. I will raise a pull request.

// Modified Code
err = copyFile(pdfPath, outputFile)
if err != nil {
    fmt.Fprintf(os.Stderr, "Error moving output file: %v\\n", err)
    os.Exit(1)
}

// Function to copy files
func copyFile(src, dst string) error {
    sourceFile, err := os.Open(src)
    if err != nil {
        return err
    }
    defer sourceFile.Close()

    destFile, err := os.Create(dst)
    if err != nil {
        return err
    }
    defer destFile.Close()

    _, err = io.Copy(destFile, sourceFile)
    if err != nil {
        return err
    }

    return destFile.Sync()
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant