The std.file rename method fails in the docker environment.
zoujiaqing
zoujiaqing at gmail.com
Wed Mar 13 21:49:55 UTC 2024
On Wednesday, 13 March 2024 at 21:21:21 UTC, Jonathan M Davis
wrote:
> On Wednesday, March 13, 2024 3:03:30 PM MDT zoujiaqing via
> Digitalmars-d-learn wrote:
>> upload file to server in docker, but upload directory volume
>> to host machine.
>>
>> Exception error:
>> ```
>> Invalid cross-device link
>> ```
>>
>> Have other function like move(a, b) ?
>>
>> https://github.com/huntlabs/hunt-framework/blob/master/source/hunt/framework /file/File.d#L102
>
> Well, the subject of your post mentions std.file, and then you
> link to a framework that does basically the same thing. So, I
> don't know what you're actually using.
>
> However, both of those functions use the OS function, rename,
> which renames the file within a file system, but it can't move
> files across file systems. Strictly speaking, it's not possible
> to move a file across file systems. What a program like mv does
> when the destination is on a different file system from the
> source file is copy the file and then delete the original. So,
> if you want to "move" a file across file systems within your
> program, you'll have to do the same thing.
>
> There may be a projcet on code.dlang.org which has a function
> which tries to move the file within the file system and then
> does a copy and remove instead if moving within the file system
> doesn't work, but otherwise, you'll have to implement that
> yourself, which could be as simple as catching the any
> exceptions from move and then attempting to copy the file and
> then remove it if an exception was thrown.
>
> - Jonathan M Davis
this is bug in D.
Docker run app code:
```d
reanme("/tmp/aaa", "/data/attachments/aaa");
```
docker volume path:
```txt
VOLUME /data/attachments
```
docker compose yml:
```yml
volumes:
- /data/attachments:/data/attachments
```
Error exception:
```
Invalid cross-device link
```
More information about the Digitalmars-d-learn
mailing list