bokket commented on issue #3724:
URL: 
https://github.com/apache/incubator-opendal/issues/3724#issuecomment-1847932182

   Hi.I look some code interested.
   The bottom line of `atomic_write_dir` is that `PathBuf::from` clones 
`Path.inner` by constructing a `Box<OsStr> of [u8]` .Then freeing the allocated 
memory afterwards. 
   But the official documentation emphasizes that this approach may not be 
safe. By referring to the `Persist` implementation of 
[tmpfile](https://github.com/Stebalien/tempfile/blob/master/src/dir.rs#L360), 
`std::mem::replace` method can make the heap memory `Box<>` empty. This is 
available at 
[fs](https://github.com/apache/incubator-opendal/blob/main/core/src/services/fs/backend.rs#L118)
 and also is implemented. In addition to 
[stackoverflow](https://stackoverflow.com/questions/70362352/atomic-file-create-write):
   1. file locking may be more appropriate for multi-read scenarios.
   2. It is also possible to use the system call `FILE_TEMP` to use the 
system's temporary folder, but in Linux, `/tmp` is usually an in-memory 
filesystem. Best practice should create temporary files in the same directory 
as the `target + rename`. However `rename` only works if the source and target 
files are on the same filesystem. 
   3. refer to 
[build](https://github.com/apache/incubator-opendal/blob/main/core/src/services/hdfs/backend.rs#L119)
 and 
[hdrs](https://github.com/apache/incubator-opendal/blob/main/core/src/services/hdfs/backend.rs#L148.
 )My idea is to add a usage similar method like [fs::atomic_write_dir 
](https://github.com/Xuanwo/hdrs/blob/main/src/client.rs#L443)above `hdrs`, 
whether or not to redesign an api will be discussed and evaluated later.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to