mirror of
https://github.com/abraunegg/onedrive
synced 2024-06-09 01:12:29 +02:00
Add file access check for file upload (#116)
* Add a check to validate that we can read the file by reading the first 10MB when uploading a new file or resuming an upload
This commit is contained in:
parent
6a5ab5607a
commit
e0b1b595e4
|
@ -1124,6 +1124,10 @@ final class SyncEngine
|
||||||
//auto maxUploadFileSize = 21474836480; // 20GB
|
//auto maxUploadFileSize = 21474836480; // 20GB
|
||||||
auto thisFileSize = getSize(path);
|
auto thisFileSize = getSize(path);
|
||||||
|
|
||||||
|
// Can we read the file - as a permissions issue or file corruption will cause a failure
|
||||||
|
// https://github.com/abraunegg/onedrive/issues/113
|
||||||
|
if (readLocalFile(path)){
|
||||||
|
// able to read the file
|
||||||
if (thisFileSize <= maxUploadFileSize){
|
if (thisFileSize <= maxUploadFileSize){
|
||||||
// Resolves: https://github.com/skilion/onedrive/issues/121, https://github.com/skilion/onedrive/issues/294, https://github.com/skilion/onedrive/issues/329
|
// Resolves: https://github.com/skilion/onedrive/issues/121, https://github.com/skilion/onedrive/issues/294, https://github.com/skilion/onedrive/issues/329
|
||||||
|
|
||||||
|
@ -1264,6 +1268,7 @@ final class SyncEngine
|
||||||
log.log("Skipping uploading this new file as it exceeds the maximum size allowed by OneDrive: ", path);
|
log.log("Skipping uploading this new file as it exceeds the maximum size allowed by OneDrive: ", path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void uploadDeleteItem(Item item, string path)
|
private void uploadDeleteItem(Item item, string path)
|
||||||
{
|
{
|
||||||
|
|
12
src/upload.d
12
src/upload.d
|
@ -1,7 +1,6 @@
|
||||||
import std.algorithm, std.conv, std.datetime, std.file, std.json;
|
import std.algorithm, std.conv, std.datetime, std.file, std.json;
|
||||||
import std.stdio, core.thread;
|
import std.stdio, core.thread;
|
||||||
import progress;
|
import progress, onedrive, util;
|
||||||
import onedrive;
|
|
||||||
static import log;
|
static import log;
|
||||||
|
|
||||||
private long fragmentSize = 10 * 2^^20; // 10 MiB
|
private long fragmentSize = 10 * 2^^20; // 10 MiB
|
||||||
|
@ -63,6 +62,10 @@ struct UploadSession
|
||||||
log.vlog("The file does not exist anymore");
|
log.vlog("The file does not exist anymore");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
// Can we read the file - as a permissions issue or file corruption will cause a failure on resume
|
||||||
|
// https://github.com/abraunegg/onedrive/issues/113
|
||||||
|
if (readLocalFile(session["localPath"].str)){
|
||||||
|
// able to read the file
|
||||||
// request the session status
|
// request the session status
|
||||||
JSONValue response;
|
JSONValue response;
|
||||||
try {
|
try {
|
||||||
|
@ -82,6 +85,11 @@ struct UploadSession
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
} else {
|
||||||
|
// unable to read the local file
|
||||||
|
remove(sessionFilePath);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
17
src/util.d
17
src/util.d
|
@ -12,6 +12,7 @@ import std.string;
|
||||||
import std.algorithm;
|
import std.algorithm;
|
||||||
import std.uri;
|
import std.uri;
|
||||||
import qxor;
|
import qxor;
|
||||||
|
static import log;
|
||||||
|
|
||||||
private string deviceName;
|
private string deviceName;
|
||||||
|
|
||||||
|
@ -129,6 +130,22 @@ bool testNetwork()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Can we read the file - as a permissions issue or file corruption will cause a failure
|
||||||
|
// https://github.com/abraunegg/onedrive/issues/113
|
||||||
|
// returns true if file can be accessed
|
||||||
|
bool readLocalFile(string path)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
// attempt to read the first 10MB of the file
|
||||||
|
read(path,10000000);
|
||||||
|
} catch (std.file.FileException e) {
|
||||||
|
// unable to read the new local file
|
||||||
|
log.log("Skipping uploading this file as it cannot be read (file permissions or file corruption): ", path);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// calls globMatch for each string in pattern separated by '|'
|
// calls globMatch for each string in pattern separated by '|'
|
||||||
bool multiGlobMatch(const(char)[] path, const(char)[] pattern)
|
bool multiGlobMatch(const(char)[] path, const(char)[] pattern)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue