Set_permissions not working

i have this function:

pub fn create_user(name: &str, password: &str) -> Result<(), String> {
  let location = get_user_dir(name, password);
    if location.exists(){return Err(String::from("user already exists"));}
    else {
        let err = create_dir(location.as_path());
        if err.is_err() {return Err(err.unwrap_err().to_string());}
    }
    let mut permissions = metadata(&location).unwrap().permissions();
    permissions.set_readonly(false);
    let err = set_permissions(location, permissions);
    if err.is_err() {return Err(err.unwrap_err().to_string());}
    return Ok(());
}

as you can see, this function is supposed to create a directory and make sure it doesn't have readonly permissions. but when i look at the directory it made:
image
i have no idea why does this happen, and it competently breaks my code, since any attempt to create a file and write into it fails and says it was unable to write into the file. could anyone please explain to me what am i doing wrong?

I notice that your prompt says "only applies to files in folder". Perhaps you only made the folder itself read-write, and the files are governed by a different property? Does it look different if you don't call set_permissions?

the directory doesn't seem to change, and i also think that this could be attribute related, but that contradicts the docs, in which it says:

This function currently corresponds to the chmod function on Unix and the SetFileAttributes function on Windows.

so on windows, the set_permissions function should be the same as setting attributes, and therefore there shouldn't be any issues with the function unless windows itself is at fault

In the Windows documentation for set_readonly, it indicates that the flag doesn't really do anything for directories (and Microsoft's documentation says something similar), so it's likely that's what you are encountering. I'm not sure what the correct way to change whether or not you can write to a folder on Windows is though.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.