简体   繁体   中英

Why RootTools cp command don't work?

I'm trying to make a copy of a file in the etc folder, for that I use the next code in a button:

changeNTP.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    File exists = new File("/etc/gps.conf");
                    if (exists.exists()) {
                        // We make a backup first
                        CommandCapture command = new CommandCapture(0, "cp -f /etc/gps.conf /etc/gps" + System.currentTimeMillis() + ".conf");
                        try {
                            RootTools.getShell(true).add(command);
                        } catch (IOException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        } catch (TimeoutException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        } catch (RootDeniedException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                        // Last time that file was modified
                        //Date filedate = new Date(exists.lastModified());
                    }
                }

            });

Well, the problem is that it doesn't copy anything. What could be the problem?

Thanks.

Ok, the next is best solution:

int date = (int) System.currentTimeMillis();
String source = "/system/etc/gps.conf";
String destination = "/system/etc/gps" + date + ".conf";

if(RootTools.remount("/system/etc/", "rw")){
   RootTools.copyFile(source, destination, true, true);
}

The problem is that previously I pointed to /etc, but this location is a symlink, the real path is /system/etc. Obviously we can't change mount type of a symlink, so, the previous code that I just have posted, is the good answer.

Thanks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM