sandreas / m4b-tool

m4b-tool is a command line utility to merge, split and chapterize audiobook files such as mp3, ogg, flac, m4a or m4b
MIT License
1.18k stars 76 forks source link

Docker: PHP Permissions Denied Error on Rename #260

Closed jtbrough closed 4 months ago

jtbrough commented 4 months ago

Hello,

Error:

PHP Warning:  rename(Output.m4b): Failed to open stream: Permission denied in phar:///usr/local/bin/m4b-tool-pre/src/library/Command/MergeCommand.php on line 983
PHP Warning:  rename(/tmp/m4b-tool/tmp_Output.m4b,Output.m4b): Permission denied in phar:///usr/local/bin/m4b-tool-pre/src/library/Command/MergeCommand.php on line 983
Could not rename output file from /tmp/m4b-tool/tmp_Output.m4b to Output.m4b
an error occured, that has not been caught:
Array
(
    [type] => 2
    [message] => rename(/tmp/m4b-tool/tmp_Output.m4b,Output.m4b): Permission denied
    [file] => phar:///usr/local/bin/m4b-tool-pre/src/library/Command/MergeCommand.php
    [line] => 983
)

Alias: alias m4b-tool='docker run -it --rm -u $(id -u):$(id -g) -v "$(pwd)":/mnt sandreas/m4b-tool:latest'

Run Command: m4b-tool merge . --output-file Output.m4b --jobs=10

I am aware of the note about relative paths with the alias, but no combination of path / output file references I've tried seems to address this error. Happy to provide further detail or testing as needed.

Thank you for the incredibly useful tool. I've been enjoying it for many years.

sandreas commented 4 months ago

Maybe try not using . because this might cause issues regarding the path resolving.

I would create ./input/ and ./output/ directories and try this:

m4b-tool merge --jobs=10 input/ -o output/output.m4b

If this does not help, you can still try to run the batch variant, event if it is only one single audio book. Here is my personal config for paths like input/Fantasy/J.K.Rowling/Harry Potter and the Philosophers stone:

m4b-tool merge --jobs=10 --batch-pattern="input/%g/%a/%n/" --batch-pattern-path="input/" "input/" --output-file="output/" --max-chapter-length=300,900 --adjust-for-ipod --audio-channels=1 --audio-bitrate=64k --audio-samplerate=22050 --audio-codec=libfdk_aac --audio-profile=aac_he --equate=name,album --ignore-source-tags --prepend-series-to-longdesc --silence-min-length=1000 --chapter-algo=grouping --skip-cover-if-exists
jtbrough commented 4 months ago

Thanks for that.

Interestingly...

m4b-tool merge input/ -o output/output.m4b --jobs=10

still results in:

PHP Warning:  rename(output/output.m4b): Failed to open stream: Permission denied in phar:///usr/local/bin/m4b-tool-pre/src/library/Command/MergeCommand.php on line 983
PHP Warning:  rename(/tmp/m4b-tool/tmp_output.m4b,output/output.m4b): Permission denied in phar:///usr/local/bin/m4b-tool-pre/src/library/Command/MergeCommand.php on line 983
Could not rename output file from /tmp/m4b-tool/tmp_output.m4b to output/output.m4b
an error occured, that has not been caught:
Array
(
    [type] => 2
    [message] => rename(/tmp/m4b-tool/tmp_output.m4b,output/output.m4b): Permission denied
    [file] => phar:///usr/local/bin/m4b-tool-pre/src/library/Command/MergeCommand.php
    [line] => 983
)

and just to share the working directories:

Permissions Size User     Date Modified Name
drwxrwxr-x     - jtbrough  7 Jul 18:39  input
drwxrwxr-x     - jtbrough  7 Jul 18:39  output
sandreas commented 4 months ago

still results in:

Strange... I'll try to EXACTLY reproduce that, but I don't think this is a problem of m4b-tool, but more of a messed up permissions situation...

You could try to debug this using the m4b-tool alias command and specifying an entry point of the shell, to "login" into the docker image and try to create files in the according directories

# "login" into the docker image shell
docker run --entrypoint /bin/ash -it ...<m4b-tool-alias-command>

# check permissions
cd /mnt/input
touch testfile

# run m4b-tool manually
m4b-tool merge --jobs=10 input/ -o output/output.m4b

The next thing you could try is to leave out the user mapping to run the docker image as root:

# leave out the  -u $(id -u):$(id -g)
alias m4b-tool='docker run -it --rm -v "$(pwd)":/mnt sandreas/m4b-tool:latest'

# run the merge
m4b-tool merge --jobs=10 input/ -o output/output.m4b

I report back if I can reproduce the problem on my system.

jtbrough commented 4 months ago

Well, removing the user mapping did the trick.

From alias m4b-tool='docker run -it --rm -u $(id -u):$(id -g) -v "$(pwd)":/mnt sandreas/m4b-tool:latest'

To alias m4b-tool='docker run -it --rm -v "$(pwd)":/mnt sandreas/m4b-tool:latest'

I'm not sure this is the ideal state, but it is working great now. I really appreciate your help, and the project.

sandreas commented 4 months ago

Great, thanks for the feedback.