Repository: helix-editor/helix
File: helix-view/src/document.rs (Rust)

Code before:
                    if force {
                        std::fs::DirBuilder::new().recursive(true).create(parent)?;
                    } else {
                        bail!("can't save file, parent directory does not exist (use :w! to create it)");
                    }
                }
            }

            // Protect against overwriting changes made externally
            if !force {
                if let Ok(metadata) = fs::metadata(&path).await {
                    if let Ok(mtime) = metadata.modified() {
                        if last_saved_time < mtime {
                            bail!("file modified by an external process, use :w! to overwrite");
                        }
                    }
                }
            }

            if readonly(&path) {
                bail!(std::io::Error::new(
                    std::io::ErrorKind::PermissionDenied,
                    "Path is read only"
                ));
            }
            let write_path = std::fs::read_link(&path).unwrap_or_else(|_| path.clone());
            let backup = if path.exists() {
                let path_ = write_path.clone();
                // hacks: we use tempfile to handle the complex task of creating
                // non clobbered temporary path for us we don't want
                // the whole automatically delete path on drop thing
                // since the path doesn't exist yet, we just want
                // the path
                tokio::task::spawn_blocking(move || -> Option<PathBuf> {
                    tempfile::Builder::new()
                        .prefix(path_.file_name()?)
                        .suffix(".bck")
                        .make_in(path_.parent()?, |backup| std::fs::rename(&path_, backup))
                        .ok()?
                        .into_temp_path()
                        .keep()
                        .ok()
                })
                .await
                .ok()
                .flatten()
            } else {
                None
            };

            let write_result: anyhow::Result<_> = async {

Review comment (suggestion):

```suggestion
            let write_path = tokio::fs::read_link(&path).await.unwrap_or_else(|_| path.clone());
```
use the tokio function insteadt

Code after:
                    if force {
                        std::fs::DirBuilder::new().recursive(true).create(parent)?;
                    } else {
                        bail!("can't save file, parent directory does not exist (use :w! to create it)");
                    }
                }
            }

            // Protect against overwriting changes made externally
            if !force {
                if let Ok(metadata) = fs::metadata(&path).await {
                    if let Ok(mtime) = metadata.modified() {
                        if last_saved_time < mtime {
                            bail!("file modified by an external process, use :w! to overwrite");
                        }
                    }
                }
            }
            let write_path = tokio::fs::read_link(&path)
                .await
                .unwrap_or_else(|_| path.clone());

            if readonly(&write_path) {
                bail!(std::io::Error::new(
                    std::io::ErrorKind::PermissionDenied,
                    "Path is read only"
                ));
            }
            let backup = if path.exists() {
                let path_ = write_path.clone();
                // hacks: we use tempfile to handle the complex task of creating
                // non clobbered temporary path for us we don't want
                // the whole automatically delete path on drop thing
                // since the path doesn't exist yet, we just want
                // the path
                tokio::task::spawn_blocking(move || -> Option<PathBuf> {
                    tempfile::Builder::new()
                        .prefix(path_.file_name()?)
                        .suffix(".bck")
                        .make_in(path_.parent()?, |backup| std::fs::rename(&path_, backup))
                        .ok()?
                        .into_temp_path()
                        .keep()
                        .ok()
                })
                .await
                .ok()
                .flatten()
            } else {
                None
            };