async fn upload_files(
        &self,
        folder: impl AsRef<Path>,
        resources: &[Resource],
        dir_mode: ArchiveMode,
    ) -> anyhow::Result<Vec<DatasetUploadFile>> {
        let mut uploads = Vec::with_capacity(resources.len());
        let folder = folder.as_ref();

        let resource_paths: HashMap<_, _> = resources
            .iter()
            .map(|x| (folder.join(&x.path), x))
            .collect();

        let mut tmp_archive_dir = None;

        let skip = &[
            Self::DATASET_METADATA_FILE,
            Self::OLD_DATASET_METADATA_FILE,
            Self::KERNEL_METADATA_FILE,
        ];

        for (entry, resource) in resource_paths {
            if !entry.exists() {
                continue;
            }
            let file_name = entry
                .file_name()
                .context("File path terminates in `..`")?
                .to_str()
                .context("File name is not valid unicode")?
                .to_string();

            let mut upload = None;

            if entry.is_file() {
                if skip.contains(&file_name.as_str()) {
                    continue;
                }
                upload = Some(entry);
            } else if entry.is_dir() {
                if tmp_archive_dir.is_none() {
                    tmp_archive_dir = Some(TempDir::new("kaggle-upload")?);
                }
                let archive_path = tmp_archive_dir.as_ref().unwrap().path().join(&file_name);
                upload = dir_mode.make_archive(entry, &archive_path)?;
            }

            if let Some(upload) = upload {
                let upload_file = self
                    .upload_dataset_file(upload, &file_name, Some(&resource))
                    .await?;
                uploads.push(upload_file);
            }
        }
        if let Some(tmp) = tmp_archive_dir {
            // release all temporary archives
            tmp.close()?;
        }

        Ok(uploads)
    }
/// Upload files in a folder.
Upload files in a folder.
Upload files in a folder .
async fn upload_files(
        &self,
        folder: impl AsRef<Path>,
        resources: &[Resource],
        dir_mode: ArchiveMode,
    ) -> anyhow::Result<Vec<DatasetUploadFile>> {
        let mut uploads = Vec::with_capacity(resources.len());
        let folder = folder.as_ref();
        let resource_paths: HashMap<_, _> = resources
            .iter()
            .map(|x| (folder.join(&x.path), x))
            .collect();
        let mut tmp_archive_dir = None;
        let skip = &[
            Self::DATASET_METADATA_FILE,
            Self::OLD_DATASET_METADATA_FILE,
            Self::KERNEL_METADATA_FILE,
        ];
        for (entry, resource) in resource_paths {
            if !entry.exists() {
                continue;
            }
            let file_name = entry
                .file_name()
                .context("File path terminates in `..`")?
                .to_str()
                .context("File name is not valid unicode")?
                .to_string();
            let mut upload = None;
            if entry.is_file() {
                if skip.contains(&file_name.as_str()) {
                    continue;
                }
                upload = Some(entry);
            } else if entry.is_dir() {
                if tmp_archive_dir.is_none() {
                    tmp_archive_dir = Some(TempDir::new("kaggle-upload")?);
                }
                let archive_path = tmp_archive_dir.as_ref().unwrap().path().join(&file_name);
                upload = dir_mode.make_archive(entry, &archive_path)?;
            }
            if let Some(upload) = upload {
                let upload_file = self
                    .upload_dataset_file(upload, &file_name, Some(&resource))
                    .await?;
                uploads.push(upload_file);
            }
        }
        if let Some(tmp) = tmp_archive_dir {
            // release all temporary archives
            tmp.close()?;
        }
        Ok(uploads)
    }
async fn upload_files ( & self , folder : impl AsRef < Path > , resources : & [ Resource ] , dir_mode : ArchiveMode , ) -> anyhow :: Result < Vec < DatasetUploadFile > > { let mut uploads = Vec :: with_capacity ( resources . len ( ) ) ; let folder = folder . as_ref ( ) ; let resource_paths : HashMap < _ , _ > = resources . iter ( ) . map ( | x | ( folder . join ( & x . path ) , x ) ) . collect ( ) ; let mut tmp_archive_dir = None ; let skip = & [ Self :: DATASET_METADATA_FILE , Self :: OLD_DATASET_METADATA_FILE , Self :: KERNEL_METADATA_FILE , ] ; for ( entry , resource ) in resource_paths { if ! entry . exists ( ) { continue ; } let file_name = entry . file_name ( ) . context ( " " ) ? . to_str ( ) . context ( " " ) ? . to_string ( ) ; let mut upload = None ; if entry . is_file ( ) { if skip . contains ( & file_name . as_str ( ) ) { continue ; } upload = Some ( entry ) ; } else if entry . is_dir ( ) { if tmp_archive_dir . is_none ( ) { tmp_archive_dir = Some ( TempDir :: new ( " " ) ? ) ; } let archive_path = tmp_archive_dir . as_ref ( ) . unwrap ( ) . path ( ) . join ( & file_name ) ; upload = dir_mode . make_archive ( entry , & archive_path ) ? ; } if let Some ( upload ) = upload { let upload_file = self . upload_dataset_file ( upload , & file_name , Some ( & resource ) ) . await ? ; uploads . push ( upload_file ) ; } } if let Some ( tmp ) = tmp_archive_dir { // release all temporary archives tmp . close ( ) ? ; } Ok ( uploads ) }
Upload files in a folder.
Upload files in a folder .
&self
folder
impl AsRef<Path>
resources
&[Resource]
dir_mode
ArchiveMode
&self
folder
impl AsRef<Path>
resources
&[Resource]
dir_mode
ArchiveMode