Application initiated file copy command does not work in macOS Catalina & Big Sur
What API are you using to do the copy?
When it fails, do you get an error? If so, what is that error?
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"
public static void copyFile(File src, File dest) throws Exception
{
InputStream in = new FileInputStream(src);
OutputStream out = new FileOutputStream(dest);
// Transfer bytes from in to out 1000k buffer
byte[] buf = new byte[1024 * 1000];
int len;
while ((len = in.read(buf)) > 0)
out.write(buf, 0, len);
out.flush();
in.close();
out.close();
}
Code is pretty basic java code that writes bytes from a source to a destination.
I was specifically referring to the App Sandbox (but also see App Sandbox Design Guide which has more details).I am not sure what you mean by "is your app sandboxed".
Oh, you coulda mentioned that earlier (-: Java is weird for all sorts of reasons.Code is pretty basic java code
Does this code throw an exception? If so, what?No error is displayed.
In a typical case what are the source and destination paths?
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"
2021-04-29 23:09:41,071 ERROR com.hrc.utilities.Helper (Helper.java:1272) Could not copy from ../../../.. to /Users/matt/Desktop/Jones Merle M 04.29.2021
java.lang.NullPointerException
at com.hrc.utilities.Helper.copyDirectory(Helper.java:1252)
at com.hrc.common.BackupFacade.backup(BackupFacade.java:69)
at com.hrc.ui.util.DialogDisplayHub$5.doInBackground(DialogDisplayHub.java:922)
at com.hrc.ui.util.DialogDisplayHub$5.doInBackground(DialogDisplayHub.java:910)
at org.jdesktop.swingworker.SwingWorker$1.call(Unknown Source)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at org.jdesktop.swingworker.SwingWorker.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Again, as a sanity check, I ran the same backup code (i.e. straight file copy from source to destination) on Mojave with no issues. The source is from a USB drive (where the portable application runs) and the destination is to the local workstation drive folder the user chooses. Only difference here is the environment of Mojave and Big Sur.
Well, that’s not very helpful. I was hoping that the Java exception would give you some clue as to what’s going on at the file system layer, but a null pointer exception just means that the Java code got itself confused and crashed.java.lang.NullPointerException
OK, based on the destination path it’s very likely that you’re tripping over the mandatory access control stuff that I discuss in On File System Permissions. However, it’s hard to be sure because of the above-mentioned failure.Could not copy from ../../../.. to /Users/matt/Desktop/Jones Merle M 04.29.2021
There’s two questions you need answered here:
Why are you getting a null pointer exception? Looking at the source of that exception it seems to be in your code (com.hrc.utilities.Helper.copyDirectory). My guess is that some file system call has failed with EPERM and this code has then crashed trying to handle that error, but that’s just a guess. The only way to know for sure is to debug it at the Java level.
Why are you not getting the MAC prompt? I’ve seen problems like this before and they are usually the result of a packaging issue, that is, your app is structured in a way that confuses the MAC system. I recommend that you escalate this via the support channel for you Java runtime. It’s likely that they’ve seen it before and know the resolution.
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"