Skip to content
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

Log : add inconsistent part size #153

Merged
merged 2 commits into from
Dec 27, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public Thread newThread(Runnable runnable) {
protected OSSProgressCallback<Request> mProgressCallback;
protected int[] mPartAttr = new int[2];
protected String mUploadFilePath;
protected long mLastPartSize;//最后一个分片的大小

public BaseMultipartUploadTask(InternalRequestOperation operation, Request request,
OSSCompletedCallback<Request, Result> completedCallback,
Expand Down Expand Up @@ -351,6 +352,9 @@ protected void checkPartSize(int[] partAttr) {

OSSLog.logDebug("[checkPartSize] - partNumber : " + partNumber);
OSSLog.logDebug("[checkPartSize] - partSize : " + (int) partSize);

long lastPartSize = mFileLength % partSize;
mLastPartSize = lastPartSize == 0 ? partSize : lastPartSize;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public class ResumableUploadTask extends BaseMultipartUploadTask<ResumableUpload
private OSSSharedPreferences mSp;
private File mCRC64RecordFile;


Copy link
Contributor

@binghaiwang binghaiwang Dec 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

多余的空行

public ResumableUploadTask(ResumableUploadRequest request,
OSSCompletedCallback<ResumableUploadRequest, ResumableUploadResult> completedCallback,
ExecutionContext context, InternalRequestOperation apiOperation) {
Expand Down Expand Up @@ -116,6 +117,8 @@ protected void initMultipartUploadId() throws IOException, ClientException, Serv
isTruncated = result.isTruncated();
nextPartNumberMarker = result.getNextPartNumberMarker();
List<PartSummary> parts = result.getParts();
int partSize = mPartAttr[0];
int partTotalNumber = mPartAttr[1];
for (int i = 0; i < parts.size(); i++) {
PartSummary part = parts.get(i);
PartETag partETag = new PartETag(part.getPartNumber(), part.getETag());
Expand All @@ -128,6 +131,17 @@ protected void initMultipartUploadId() throws IOException, ClientException, Serv
}
OSSLog.logDebug("[initUploadId] - " + i + " part.getPartNumber() : " + part.getPartNumber());
OSSLog.logDebug("[initUploadId] - " + i + " part.getSize() : " + part.getSize());

if (part.getPartNumber() == partTotalNumber){
Copy link
Contributor

@binghaiwang binghaiwang Dec 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

boolean isTotal = part.getPartNumber() == partTotalNumber;

 if (isTotal && part.getSize() != mLastPartSize){
                                    throw new ClientException("current part size " + partSize + " setting is inconsistent with PartSize : " + mPartAttr[0] + " or lastPartSize : " + mLastPartSize);
                                }

if (!isTotal && part.getSize() != partSize){
                                    throw new ClientException("current part size " + partSize + " setting is inconsistent with PartSize : " + mPartAttr[0] + " or lastPartSize : " + mLastPartSize);
                                }
                            }

这样 少一个if else 会不会更好呢

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea

if (part.getSize() != mLastPartSize){
throw new ClientException("current part size " + partSize + " setting is inconsistent with PartSize : " + mPartAttr[0] + " or lastPartSize : " + mLastPartSize);
}
}else{
if (part.getSize() != partSize){
throw new ClientException("current part size " + partSize + " setting is inconsistent with PartSize : " + mPartAttr[0] + " or lastPartSize : " + mLastPartSize);
}
}

mPartETags.add(partETag);
mUploadedLength += part.getSize();
mAlreadyUploadIndex.add(part.getPartNumber());
Expand Down Expand Up @@ -187,11 +201,11 @@ protected ResumableUploadResult doMultipartUpload() throws IOException, ClientEx
throw new ClientException("The uploading file is inconsistent with before");
}

long firstPartSize = mPartETags.get(0).getPartSize();
OSSLog.logDebug("[initUploadId] - firstPartSize : " + firstPartSize);
if (firstPartSize > 0 && firstPartSize != readByte && firstPartSize < mFileLength) {
throw new ClientException("current part size " + readByte + " setting is inconsistent with before " + firstPartSize);
}
// long firstPartSize = mPartETags.get(0).getPartSize();
// OSSLog.logDebug("[initUploadId] - firstPartSize : " + firstPartSize);
// if (firstPartSize > 0 && firstPartSize != readByte && firstPartSize < mFileLength) {
// throw new ClientException("current part size " + readByte + " setting is inconsistent with before " + firstPartSize);
// }

long revertUploadedLength = mUploadedLength;

Expand Down