<commit_before>package com.afollestad.cabinet.file.root;

import android.app.Activity;
import android.util.Log;

import com.afollestad.cabinet.R;
import com.afollestad.cabinet.file.LocalFile;
import com.afollestad.cabinet.file.base.File;
import com.afollestad.cabinet.file.base.FileFilter;
import com.afollestad.cabinet.sftp.SftpClient;
import com.afollestad.cabinet.utils.Utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

import eu.chainfire.libsuperuser.Shell;

public class RootFile extends File {

    public RootFile(Activity context) {
        super(context, null);
    }

    public RootFile(Activity context, String path, String name) {
        super(context, path + "/" + name);
        setPath(path + "/" + name);
    }

    public String permissions;
    public String owner;
    public String creator;
    public long size = -1;
    public String date;
    public String time;
    public String originalName;

    @Override
    public boolean isHidden() {
        return getName().startsWith(".");
    }

    @Override
    public File getParent() {
        java.io.File mFile = new java.io.File(getPath());
        return new RootFile(getContext(), mFile.getParent(), mFile.getName());
    }

    @Override
    public void createFile(final SftpClient.CompletionCallback callback) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    runAsRoot("touch \"" + getPath() + "\"");
                    callback.onComplete();
                } catch (Exception e) {
                    e.printStackTrace();
                    callback.onError(e);
                }
            }
        }).start();
    }

    @Override
    public void mkdir(final SftpClient.CompletionCallback callback) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    runAsRoot("mkdir -P \"" + getPath() + "\"");
                    callback.onComplete();
                } catch (Exception e) {
                    e.printStackTrace();
                    callback.onError(e);
                }
            }
        }).start();
    }

    @Override
    public void rename(File newFile, final SftpClient.CompletionCallback callback) {
        Utils.checkDuplicates(getContext(), newFile, new Utils.DuplicateCheckResult() {
            @Override
            public void onResult(final File newFile) {
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            runAsRoot("mv -f \"" + getPath() + "\" \"" + newFile.getPath() + "\"");
                            getContext().runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    setPath(newFile.getPath());
                                    callback.onComplete();
                                    notifyMediaScannerService(newFile);
                                }
                            });
                        } catch (final Exception e) {
                            e.printStackTrace();
                            getContext().runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    Utils.showErrorDialog(getContext(), R.string.failed_rename_file, e);
                                    callback.onError(null);
                                }
                            });
                        }
                    }
                }).start();
            }
        });
    }

    @Override
    public void copy(final File dest, final SftpClient.FileCallback callback) {
        Utils.checkDuplicates(getContext(), dest, new Utils.DuplicateCheckResult() {
            @Override
            public void onResult(final File dest) {
                try {
                    runAsRoot("cp -R \"" + getPath() + "\" \"" + dest.getPath() + "\"");
                    getContext().runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            callback.onComplete(dest);
                        }
                    });
                } catch (final Exception e) {
                    e.printStackTrace();
                    getContext().runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Utils.showErrorDialog(getContext(), R.string.failed_copy_file, e);
                            callback.onError(null);
                        }
                    });
                }
            }
        });
    }

    @Override
    public void delete(final SftpClient.CompletionCallback callback) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    deleteSync();
                    getContext().runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            if (callback != null) callback.onComplete();
                        }
                    });
                } catch (final Exception e) {
                    e.printStackTrace();
                    getContext().runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Utils.showErrorDialog(getContext(), R.string.failed_delete_file, e);
                            if (callback != null) callback.onError(null);
                        }
                    });
                }
            }
        }).start();
    }

    @Override
    public boolean deleteSync() throws Exception {
        runAsRoot("rm -rf \"" + getPath() + "\"");
        return true;
    }

    @Override
    public boolean isRemote() {
        return false;
    }

    @Override
    public boolean isDirectory() {
        return size == -1;
    }

    @Override
    public void exists(final BooleanCallback callback) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    final boolean exists = existsSync();<commit_msg>Fixes<commit_after>package com.afollestad.cabinet.file.root;

import android.app.Activity;
import android.util.Log;

import com.afollestad.cabinet.R;
import com.afollestad.cabinet.file.LocalFile;
import com.afollestad.cabinet.file.base.File;
import com.afollestad.cabinet.file.base.FileFilter;
import com.afollestad.cabinet.sftp.SftpClient;
import com.afollestad.cabinet.utils.Utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

import eu.chainfire.libsuperuser.Shell;

public class RootFile extends File {

    public RootFile(Activity context) {
        super(context, null);
    }

    public RootFile(Activity context, String path, String name) {
        super(context, path + "/" + name);
        setPath(path + "/" + name);
    }

    public String permissions;
    public String owner;
    public String creator;
    public long size = -1;
    public String date;
    public String time;
    public String originalName;

    @Override
    public boolean isHidden() {
        return getName().startsWith(".");
    }

    @Override
    public File getParent() {
        java.io.File mFile = new java.io.File(getPath());
        return new RootFile(getContext(), mFile.getParent(), mFile.getName());
    }

    @Override
    public void createFile(final SftpClient.CompletionCallback callback) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    runAsRoot("touch \"" + getPath() + "\"");
                    callback.onComplete();
                } catch (Exception e) {
                    e.printStackTrace();
                    callback.onError(e);
                }
            }
        }).start();
    }

    @Override
    public void mkdir(final SftpClient.CompletionCallback callback) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    runAsRoot("mkdir -P \"" + getPath() + "\"");
                    callback.onComplete();
                } catch (Exception e) {
                    e.printStackTrace();
                    callback.onError(e);
                }
            }
        }).start();
    }

    @Override
    public void rename(File newFile, final SftpClient.CompletionCallback callback) {
        Utils.checkDuplicates(getContext(), newFile, new Utils.DuplicateCheckResult() {
            @Override
            public void onResult(final File newFile) {
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            runAsRoot("mv -f \"" + getPath() + "\" \"" + newFile.getPath() + "\"");
                            getContext().runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    setPath(newFile.getPath());
                                    callback.onComplete();
                                    notifyMediaScannerService(newFile);
                                }
                            });
                        } catch (final Exception e) {
                            e.printStackTrace();
                            getContext().runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    Utils.showErrorDialog(getContext(), R.string.failed_rename_file, e);
                                    callback.onError(null);
                                }
                            });
                        }
                    }
                }).start();
            }
        });
    }

    @Override
    public void copy(final File dest, final SftpClient.FileCallback callback) {
        Utils.checkDuplicates(getContext(), dest, new Utils.DuplicateCheckResult() {
            @Override
            public void onResult(final File dest) {
                try {
                    runAsRoot("cp -R \"" + getPath() + "\" \"" + dest.getPath() + "\"");
                    getContext().runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            callback.onComplete(dest);
                        }
                    });
                } catch (final Exception e) {
                    e.printStackTrace();
                    getContext().runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Utils.showErrorDialog(getContext(), R.string.failed_copy_file, e);
                            callback.onError(null);
                        }
                    });
                }
            }
        });
    }

    @Override
    public void delete(final SftpClient.CompletionCallback callback) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    deleteSync();
                    getContext().runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            if (callback != null) callback.onComplete();
                        }
                    });
                } catch (final Exception e) {
                    e.printStackTrace();
                    getContext().runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Utils.showErrorDialog(getContext(), R.string.failed_delete_file, e);
                            if (callback != null) callback.onError(null);
                        }
                    });
                }
            }
        }).start();
    }

    @Override
    public boolean deleteSync() throws Exception {
        String deleteCmd = "rm -f \"" + getPath() + "\"";
        if (isDirectory()) {
            deleteCmd = "rm -rf \"" + getPath() + "\"";
        }
        runAsRoot(deleteCmd);
        return true;
    }

    @Override
    public boolean isRemote() {
        return false;
    }

    @Override
    public boolean isDirectory() {
        return size == -1;
    }

    @Override
    public void exists(final BooleanCallback callback) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    final boolean exists = existsSync();
{'fraction_non_alphanumeric': 0.10035211267605634, 'fraction_numerical': 0.0003061849357011635, 'mean_word_length': 1.206552947137308, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6201948', 'n_tokens_mistral': 3226, 'n_tokens_neox': 3033, 'n_words': 662}