-
-
Notifications
You must be signed in to change notification settings - Fork 45
Backmerge Commcare 2.61.3 #3504
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
Changes from all commits
5bb211f
4e129b7
d7dda5d
c8b16f9
536d3cc
c3839c4
81e52ef
680dd7c
47b2830
fe50e49
01def49
4f0b903
dd74a99
bf7e580
9aa8df9
78a496f
e4110bc
eeb83ab
184ee06
2729474
5473e68
6fe9114
ec194ee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,5 +1,8 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| package org.commcare.models.encryption; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.google.firebase.perf.metrics.Trace; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.commcare.google.services.analytics.CCPerfMonitoring; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.commcare.util.LogTypes; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.javarosa.core.io.StreamsUtil; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.javarosa.core.services.Logger; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -10,6 +13,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.io.FileInputStream; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.io.FileNotFoundException; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.io.FileOutputStream; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.io.IOException; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.io.InputStream; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.io.OutputStream; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.security.InvalidKeyException; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -28,13 +32,17 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public class EncryptionIO { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public static void encryptFile(String sourceFilePath, String destPath, SecretKeySpec symetricKey) throws FileNotFoundException, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| StreamsUtil.InputIOException, StreamsUtil.OutputIOException { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public static void encryptFile(String sourceFilePath, String destPath, SecretKeySpec symetricKey) throws IOException { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Trace trace = CCPerfMonitoring.INSTANCE.startTracing(CCPerfMonitoring.TRACE_FILE_ENCRYPTION_TIME); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| OutputStream os; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| FileInputStream is; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| os = createFileOutputStream(destPath, symetricKey); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| is = new FileInputStream(sourceFilePath); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| int fileSize = is.available(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| StreamsUtil.writeFromInputToOutputNew(is, os); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CCPerfMonitoring.INSTANCE.stopFileEncryptionTracing(trace, fileSize, sourceFilePath); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+35
to
46
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Trace not stopped on exception path. If an exception occurs during the write operation, the trace will never be stopped. Consider wrapping in a try-finally to ensure the trace is always stopped. Proposed fix public static void encryptFile(String sourceFilePath, String destPath, SecretKeySpec symetricKey) throws IOException {
Trace trace = CCPerfMonitoring.INSTANCE.startTracing(CCPerfMonitoring.TRACE_FILE_ENCRYPTION_TIME);
OutputStream os;
FileInputStream is;
- os = createFileOutputStream(destPath, symetricKey);
- is = new FileInputStream(sourceFilePath);
- int fileSize = is.available();
- StreamsUtil.writeFromInputToOutputNew(is, os);
-
- CCPerfMonitoring.INSTANCE.stopFileEncryptionTracing(trace, fileSize, sourceFilePath);
+ File sourceFile = new File(sourceFilePath);
+ long fileSize = sourceFile.length();
+ try {
+ os = createFileOutputStream(destPath, symetricKey);
+ is = new FileInputStream(sourceFilePath);
+ StreamsUtil.writeFromInputToOutputNew(is, os);
+ } finally {
+ CCPerfMonitoring.INSTANCE.stopFileEncryptionTracing(trace, fileSize, sourceFilePath);
+ }
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public static OutputStream createFileOutputStream(String filename, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use
File.length()instead ofInputStream.available()for accurate file size.is.available()returns an estimate of bytes that can be read without blocking, not the actual file size. For accurate file size metrics, use the file's length directly.Proposed fix
public static void encryptFile(String sourceFilePath, String destPath, SecretKeySpec symetricKey) throws IOException { Trace trace = CCPerfMonitoring.INSTANCE.startTracing(CCPerfMonitoring.TRACE_FILE_ENCRYPTION_TIME); OutputStream os; FileInputStream is; + File sourceFile = new File(sourceFilePath); + long fileSize = sourceFile.length(); os = createFileOutputStream(destPath, symetricKey); is = new FileInputStream(sourceFilePath); - int fileSize = is.available(); StreamsUtil.writeFromInputToOutputNew(is, os); CCPerfMonitoring.INSTANCE.stopFileEncryptionTracing(trace, fileSize, sourceFilePath); }🤖 Prompt for AI Agents