修改在linux下路径的bug
This commit is contained in:
@@ -4,6 +4,16 @@
|
||||
<TargetFrameworks>netstandard2.0;netcoreapp2.0;netstandard2.1;netcoreapp3.0</TargetFrameworks>
|
||||
<RootNamespace>Ufangx.FileServices</RootNamespace>
|
||||
<AssemblyName>FileServices</AssemblyName>
|
||||
<Authors>Jackson.bruce</Authors>
|
||||
<Company>Ufangx</Company>
|
||||
<Description>File management, super large file upload, breakpoint renewal</Description>
|
||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||
<RepositoryUrl>https://github.com/JacksonBruce/FileServices.git</RepositoryUrl>
|
||||
<PackageProjectUrl>https://github.com/JacksonBruce/FileServices</PackageProjectUrl>
|
||||
<RepositoryType>git</RepositoryType>
|
||||
<PackageTags>file service web uploader html5 uploader breakpoint renewal</PackageTags>
|
||||
<Copyright>Copyright (c) 2020-$([System.DateTime]::Now.Year) Jackson.Bruce</Copyright>
|
||||
<Version>1.0.0-beta.1</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(TargetFramework)|$(Platform)'=='netstandard2.0|AnyCPU'">
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace Ufangx.FileServices.Local
|
||||
}
|
||||
protected string physicalPath(string path) {
|
||||
|
||||
return Path.Combine(option.StorageRootDir, path.Trim().Replace('/', '\\').TrimStart('\\'));
|
||||
return Path.Combine(option.StorageRootDir, path.Trim().Replace('\\', '/').TrimStart('/'));
|
||||
}
|
||||
protected bool CreateDirIfNonexistence(string path) {
|
||||
|
||||
|
||||
@@ -22,14 +22,15 @@ namespace Ufangx.FileServices.Local
|
||||
}
|
||||
string GetTempDir(string path, string key)
|
||||
{
|
||||
return Path.Combine(Path.GetDirectoryName(path), $"_tmp{key}");
|
||||
return Path.Combine(Path.GetDirectoryName(path), $"_tmp{key}").Replace('\\','/');
|
||||
}
|
||||
bool CheckFiles(string dir, long count) {
|
||||
//Console.WriteLine("正在检查文件。。。");
|
||||
//Stopwatch sw = Stopwatch.StartNew();
|
||||
for (long i = 0; i < count; i++)
|
||||
{
|
||||
if (!File.Exists(Path.Combine(dir, $"{i}"))) { return false; }
|
||||
string path = Path.Combine(dir, $"{i}").Replace('\\', '/');
|
||||
if (!File.Exists(path)) { return false; }
|
||||
}
|
||||
//sw.Stop();
|
||||
//Console.WriteLine($"检查{count}个文件,用时:{sw.Elapsed.TotalMilliseconds}毫秒");
|
||||
@@ -51,8 +52,8 @@ namespace Ufangx.FileServices.Local
|
||||
using (var fs = GetFileStream(path))
|
||||
{
|
||||
for (long i = 0; i < count; i++)
|
||||
{
|
||||
var blob = await GetBlob(Path.Combine(dir, $"{i}"), token);
|
||||
{
|
||||
var blob = await GetBlob(Path.Combine(dir, $"{i}").Replace('\\','/'), token);
|
||||
await fs.WriteAsync(blob, 0, blob.Length, token);
|
||||
}
|
||||
await fs.FlushAsync(token);
|
||||
@@ -87,7 +88,7 @@ namespace Ufangx.FileServices.Local
|
||||
}
|
||||
var p = physicalPath(info.StoreName);
|
||||
string tempdir = GetTempDir(p,info.Key);
|
||||
var tmp = Path.Combine(tempdir, $"{blob.BlobIndex}");
|
||||
var tmp = Path.Combine(tempdir, $"{blob.BlobIndex}").Replace('\\','/');
|
||||
if (CreateDirIfNonexistence(tmp))
|
||||
{
|
||||
var stream = blob.Data;
|
||||
|
||||
@@ -41,26 +41,26 @@ namespace Ufangx.FileServices.Services
|
||||
nameRule = FileNameRule.Ascending;
|
||||
}
|
||||
if (directory == null) { directory = string.Empty; }
|
||||
directory = Path.Combine(scheme?.StoreDirectory ?? string.Empty, directory);
|
||||
directory = Path.Combine(scheme?.StoreDirectory ?? string.Empty, directory).Replace('\\', '/');
|
||||
string fileName;
|
||||
switch (nameRule)
|
||||
{
|
||||
case FileNameRule.Ascending:
|
||||
fileName = Path.Combine(directory, originName);
|
||||
fileName = Path.Combine(directory, originName).Replace('\\', '/');
|
||||
int index = 0;
|
||||
while (await fileService.Exists(fileName))
|
||||
{
|
||||
fileName = Path.Combine(directory, $"{Path.GetFileNameWithoutExtension(originName)}({++index}){Path.GetExtension(originName)}");
|
||||
fileName = Path.Combine(directory, $"{Path.GetFileNameWithoutExtension(originName)}({++index}){Path.GetExtension(originName)}").Replace('\\', '/');
|
||||
}
|
||||
break;
|
||||
case FileNameRule.Date:
|
||||
fileName = Path.Combine(directory, string.Format(fileNameRuleOptions?.Format ?? "{0:yyyyMMddHHmmss}", DateTime.Now) + Path.GetExtension(originName));
|
||||
fileName = Path.Combine(directory, string.Format(fileNameRuleOptions?.Format ?? "{0:yyyyMMddHHmmss}", DateTime.Now) + Path.GetExtension(originName)).Replace('\\', '/');
|
||||
break;
|
||||
case FileNameRule.Custom:
|
||||
fileName = Path.Combine(directory, fileNameRuleOptions.Custom(originName));
|
||||
fileName = Path.Combine(directory, fileNameRuleOptions.Custom(originName)).Replace('\\', '/');
|
||||
break;
|
||||
default:
|
||||
fileName = Path.Combine(directory, originName);
|
||||
fileName = Path.Combine(directory, originName).Replace('\\', '/');
|
||||
break;
|
||||
}
|
||||
return fileName.Replace('\\', '/');
|
||||
|
||||
Reference in New Issue
Block a user