1 /* 2 * Copyright 2011, Haiku, Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Oliver Tappe <zooey@hirschkaefer.de> 7 */ 8 9 10 #include <package/FetchFileJob.h> 11 12 #include <stdlib.h> 13 #include <sys/wait.h> 14 15 #include <Path.h> 16 17 18 namespace BPackageKit { 19 20 namespace BPrivate { 21 22 23 FetchFileJob::FetchFileJob(const BContext& context, const BString& title, 24 const BString& fileURL, const BEntry& targetEntry) 25 : 26 inherited(context, title), 27 fFileURL(fileURL), 28 fTargetEntry(targetEntry) 29 { 30 } 31 32 33 FetchFileJob::~FetchFileJob() 34 { 35 } 36 37 38 status_t 39 FetchFileJob::Execute() 40 { 41 BPath targetPath; 42 status_t result = fTargetEntry.GetPath(&targetPath); 43 if (result != B_OK) 44 return result; 45 46 // TODO: implement for real, maybe using the "service kit"-GSOC HTTP-stuff? 47 BString cmd = BString("curl -# -o ") << targetPath.Path() << " " 48 << fFileURL.String(); 49 50 int cmdResult = system(cmd.String()); 51 if (WIFSIGNALED(cmdResult) 52 && (WTERMSIG(cmdResult) == SIGINT || WTERMSIG(cmdResult) == SIGQUIT)) { 53 return B_CANCELED; 54 } 55 56 return cmdResult == 0 ? B_OK : B_ERROR; 57 } 58 59 60 void 61 FetchFileJob::Cleanup(status_t jobResult) 62 { 63 if (jobResult != B_OK) 64 fTargetEntry.Remove(); 65 } 66 67 68 } // namespace BPrivate 69 70 } // namespace BPackageKit 71