Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions WordPress/src/main/java/org/wordpress/android/util/FluxCUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
* @return MediaModel or null in case of problems reading the URI
*/
@Nullable
public static MediaModel mediaModelFromLocalUri(@NonNull Context context,

Check failure on line 101 in WordPress/src/main/java/org/wordpress/android/util/FluxCUtils.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this method to reduce its Cognitive Complexity from 21 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=wordpress-mobile_WordPress-Android&issues=AZ0vegdsTa3Fdhbhjz35&open=AZ0vegdsTa3Fdhbhjz35&pullRequest=22753
@NonNull Uri uri,
@Nullable String mimeType,
@NonNull org.wordpress.android.fluxc.store.MediaStore mediaStore,
Expand Down Expand Up @@ -144,6 +144,26 @@
filename += "." + fileExtension;
}

// Path resolution can drop the file extension when the filename contains
// spaces (e.g. "screenshot_one ui home123.jpg" resolves to a path ending
// in "screenshot_one ui home123."). Rename the on-disk file so the path
// includes the correct extension, allowing upload consumers to detect the
// MIME type from the filename.
if (fileExtension != null && !path.endsWith("." + fileExtension)) {
String correctedPath = path;
while (correctedPath.endsWith(".")) {
correctedPath = correctedPath.substring(0, correctedPath.length() - 1);
}
correctedPath = correctedPath + "." + fileExtension;
File renamed = new File(correctedPath);
if (file.renameTo(renamed)) {
path = correctedPath;
} else {
AppLog.w(T.UTILS,
"Failed to rename cached file to include extension: " + path);
}
}

MediaModel media = new MediaModel(
localSiteId,
DateTimeUtils.iso8601UTCFromTimestamp(System.currentTimeMillis() / 1000),
Expand Down
Loading