Skip to content

Commit

Permalink
File.Write; S3.DownloadFile; Zip.ExtractFile should create target fol…
Browse files Browse the repository at this point in the history
…der, if needed
  • Loading branch information
dwarfland committed Jun 10, 2016
1 parent bf77943 commit ae11610
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions RemObjects.Train/API/File.pas
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ implementation
class method FilePlugin.File_Write(aServices: IApiRegistrationServices; ec: ExecutionContext;aFN, aData: String);
begin
var lVal := aServices.ResolveWithBase(ec, aFN, true);
if not System.IO.Directory.Exists(Path.GetDirectoryName(lVal)) then
Directory.CreateDirectory(Path.GetDirectoryName(lVal));
System.IO.File.WriteAllText(lVal, aData);
end;

Expand Down
5 changes: 3 additions & 2 deletions RemObjects.Train/API/S3.pas
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ implementation
lDownloadTarget := Path.Combine(lS3CacheFolder, lCleanedKey);
end;

Directory.CreateDirectory(Path.GetDirectoryName(aLocalTarget));
if not System.IO.Directory.Exists(Path.GetDirectoryName(aLocalTarget)) then
Directory.CreateDirectory(Path.GetDirectoryName(aLocalTarget));
try
using lRequest := new GetObjectRequest(BucketName := aSelf.Bucket, Key := aKey) do begin

Expand Down Expand Up @@ -254,7 +255,7 @@ implementation
aLocalFile := aServices.ResolveWithBase(ec, aLocalFile);
aKey := aServices.Expand(ec, aKey);

aKey.Replace("//", "/"); // S3 really doesn't like those.
aKey := aKey.Replace("//", "/"); // S3 really doesn't like those.
if aKey.EndsWith("/") then
aKey := aKey+Path.GetFileName(aLocalFile); // if aKey is a folder, reuse local filename

Expand Down
3 changes: 3 additions & 0 deletions RemObjects.Train/API/Zip.pas
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ implementation
if lEntry.FilenameInZip = nil then raise new ArgumentException('No such file in zip: '+aEntry:name);
if aDestinationFile.EndsWith('/') or aDestinationFile.EndsWith('\') then
aDestinationFile := Path.Combine(aDestinationFile, Path.GetFileName(aEntry.name));
if not System.IO.Directory.Exists(Path.GetDirectoryName(aDestinationFile)) then
Directory.CreateDirectory(Path.GetDirectoryName(aDestinationFile));
if File.Exists(aDestinationFile) then
File.Delete(aDestinationFile);
if not zs.ExtractFile(lEntry, aDestinationFile) then
Expand All @@ -104,6 +106,7 @@ implementation
class method ZipRegistration.ZipExtractFiles(aServices: IApiRegistrationServices;ec: ExecutionContext; zip: String; aDestinationPath: String; aEntry: array of ZipEntryData; aFlatten: Boolean := false);
begin
aDestinationPath := aServices.ResolveWithBase(ec, aDestinationPath);
Directory.CreateDirectory(aDestinationPath);
using zs := ZipStorer.Open(aServices.ResolveWithBase(ec,zip), FileAccess.Read) do begin
for each el in zs.ReadCentralDir do begin
if not ((length(aEntry) = 0) or (aEntry.Any(a->a.name = el.FilenameInZip)) ) then continue;
Expand Down

0 comments on commit ae11610

Please sign in to comment.