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

Tweak some file and register apis #2451

Closed

Conversation

happybeing
Copy link
Contributor

Description

Includes tweaks to register and file APIs which include a fix for issue 2434:

  • make dir_upload() methods more granular and a way to access the list of uploaded paths
  • add option to create a register without an initial value

Related Issue

Fixes #2434

Type of Change

Please mark the types of changes made in this pull request.

  • Bug fix (non-breaking change which fixes an issue)
  • [ x] New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Other (please describe):

Checklist

Please ensure all of the following tasks have been completed:

  • I have read the contributing guidelines.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • I have updated the documentation accordingly.
  • I have followed the conventional commits guidelines for commit messages.
  • I have verified my commit messages with commitlint.

@happybeing
Copy link
Contributor Author

Hi folks, I know it wants me to change the commit message from 'Fix' to 'fix' but I've tried multiple times and have to give up as when I do an interactive rebase I get merge conflicts that I dare not touch.

I'll have to leave this now but hope you can either fix it easily or pick up the changes some other way. Sorry for the mess.

Copy link
Member

@grumbach grumbach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent contribution as always @happybeing! Approved it, although the PR has some conflicts due to the recent renaming of everything!

@happybeing
Copy link
Contributor Author

@grumbach I'm not very good at this! I have latest main and merged it into the PR branch, resolved conflicts and have pushed. So I'm not seeing any conflicts locally.

Maybe the best way to do this is for you to just grab the following and put it into impl Client in safe_network/autonomi/src/client/fs.rs:

    /// Upload a directory to the network. The directory is recursively walked.
    /// Reads all files, splits into chunks, uploads chunks, uploads datamaps, uploads archive, returns ArchiveAddr (pointing to the archive)
    pub async fn dir_and_archive_upload(
        &self,
        dir_path: PathBuf,
        wallet: &EvmWallet,
    ) -> Result<ArchiveAddr, UploadError> {
        match self.dir_upload(dir_path.clone(), wallet).await {
            Ok(archive) => Ok(self.archive_upload(&archive, wallet).await?),
            Err(e) => Err(e),
        }
    }

    /// Upload a directory to the network. The directory is recursively walked.
    /// Reads all files, splits into chunks, uploads chunks, uploads datamaps, returns Archive but does not upload that to the network.
    pub async fn dir_upload(
        &self,
        dir_path: PathBuf,
        wallet: &EvmWallet,
    ) -> Result<Archive, UploadError> {
        info!("Uploading directory: {dir_path:?}");
        let start = tokio::time::Instant::now();

        // start upload of files in parallel
        let mut upload_tasks = Vec::new();
        for entry in walkdir::WalkDir::new(dir_path) {
            let entry = entry?;
            if !entry.file_type().is_file() {
                continue;
            }

            let metadata = metadata_from_entry(&entry);
            let path = entry.path().to_path_buf();
            upload_tasks.push(async move {
                let file = self.file_upload(path.clone(), wallet).await;
                (path, metadata, file)
            });
        }

You can forget the register change as I understand Registers are being removed and I'll be refactoring my code for Transactions once the API is in place.

My git/github skills seem to have abandoned me here. I don't understand what's going on. Sorry!

@b-zee
Copy link
Contributor

b-zee commented Dec 4, 2024

Thanks a lot for this one @happybeing. I actually looked at this last week but forgot to respond. This is high on my list! I will change these APIs with a refactor soon. You're completely right that the power user doesn't have a lot of options with the current API, so this needs some love.

I'll try and re-use your branch/commits and fix the conflicts.

@maqi
Copy link
Member

maqi commented Dec 20, 2024

Closed as @b-zee will take this into account during the API refactor work.
Some of the work may also no longer suitable as there is plan to remove Regsiter.

@maqi maqi closed this Dec 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature(CLI): Return file addresses within archive when uploading a directory
4 participants