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

Pulling a folder that contains "." in it #101

Open
itapi opened this issue Mar 26, 2024 · 16 comments
Open

Pulling a folder that contains "." in it #101

itapi opened this issue Mar 26, 2024 · 16 comments
Labels
bug Something isn't working

Comments

@itapi
Copy link

itapi commented Mar 26, 2024

Describe the bug

The new 3.2.11 release is really good,but it's still has bugs ,such as I cannot pull a folder that it's name contains dots in it(such as common package names folders).

On any other folders it works perfect!!

static AdbClient adbClient;
static DeviceData device;
private async void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
    adbClient = new AdbClient();
    adbClient.Connect("127.0.0.1:62001");
    device = adbClient.GetDevices().FirstOrDefault(); // Get first connected device
    SyncService service = new SyncService(device);

    await PullFolderAsync("/sdcard/android/data/com.globile.mycontactbackup/files", @"C:\Users\Itamar\Documents\UBL");

}
SyncService service;
async Task PullFolderAsync(string remotePath, string localPath)
{
    if (!Directory.Exists(localPath))
    {
        Directory.CreateDirectory(localPath);
    }

    service = new SyncService(device);

    FileStatistics stat = await service.StatAsync(remotePath);
    await PullFolderAsyncInternal(stat, remotePath, localPath);

}
async Task PullFolderAsyncInternal(FileStatistics stat, string remotePath, string localPath)
{
    switch (stat.get_FileMode().GetFileType())
    {
        case UnixFileStatus.Directory:
            if (remotePath != stat.Path)
            {
                localPath = System.IO.Path.Combine(localPath, stat.Path);
                remotePath = LinuxPath.Combine(remotePath, stat.Path);
            }
            if (!Directory.Exists(localPath))
            {
                Directory.CreateDirectory(localPath);
            }
            foreach (FileStatistics item in await service.GetDirectoryListingAsync(remotePath))
            {
                await PullFolderAsyncInternal(item, remotePath, localPath);
            }
            break;
        case UnixFileStatus.Regular:
            string localFilePath = System.IO.Path.Combine(localPath, stat.Path);
            using (FileStream stream = File.OpenWrite(localFilePath))
            {
                await service.PullAsync(LinuxPath.Combine(remotePath, stat.Path), stream);
                await stream.FlushAsync();
            }
            break;
    }
}

Steps to reproduce the bug

pull folders

Expected behavior

No response

Screenshots

No response

NuGet package version

None

.NET Platform

No response

Platform type

No response

System version

No response

IDE

No response

Additional context

No response

@itapi itapi added the bug Something isn't working label Mar 26, 2024
@wherewhere
Copy link
Member

🤬

@itapi
Copy link
Author

itapi commented Mar 28, 2024

@wherewhere what's so odd?
I'm trying to pull a directory,which it's name contains "."...such as in the image....

Do a test with yourself....place on the main storage path a folder and call it aaa.bbb,you'll see it's buggy...
I've investigated into the PullFolderAsyncInternal function,and I've see there's a bug in the remotePath = LinuxPath.Combine(remotePath, stat.Path); line,where it's split the path by dots,and recognize the dot as a folder....

image

@wherewhere
Copy link
Member

😔

@wherewhere
Copy link
Member

So what? ConsoleApp.zip
image

@wherewhere
Copy link
Member

Screenbits.2024-03-29_012356.2.2.mp4

@itapi
Copy link
Author

itapi commented Mar 31, 2024

@wherewhere I'm sorry,I'll be more specfic and focus the bug,in the sdcard it's indeed work,but try to pull a file from the "/sdcard/Android/data/xxxx"(any folder here-which are the external data folders for apps),you'll encouteer a bug.
I've tried to pull the outer folder,i.e "/sdcard/Android/data/",and I see it's pulling the main android root dir....

@wherewhere
Copy link
Member

This is Android promission issue. I don't know how to fix it.

@itapi
Copy link
Author

itapi commented Apr 2, 2024

@wherewhere hey bro,it's defintely nor android permission issue....because when you use this : adb pull /sdcard/android/data/com.globile.mycontactbackup/files in normal adb clil.... it works as charm... :(

@wherewhere
Copy link
Member

Why your markdown is so weird? The code block is not on codes...

@wherewhere
Copy link
Member

I still have no idea, you can use adb command line by List<string> IAdbCommandLineClient.ExecuteAdbCommand(string command)

@itapi
Copy link
Author

itapi commented Apr 8, 2024

@wherewhere thanks for solution sir,how can I involve that line in my code?
How to get the IAdbCommandLineClient interface?

@wherewhere
Copy link
Member

🤬

@wherewhere
Copy link
Member

So why not just use Process to invoke commands...

@itapi
Copy link
Author

itapi commented Apr 8, 2024

@wherewhere cmon...please....

@wherewhere
Copy link
Member

It's better to use Process because List<string> IAdbCommandLineClient.ExecuteAdbCommand(string command) set to force exit after 5s.

@itapi
Copy link
Author

itapi commented Apr 8, 2024

@wherewhere thanks sir....appriciate it.
If there would be a fix in the next versions I would like to know :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants