1 /* 2 * Copyright 2013, Haiku, Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Ingo Weinhold <ingo_weinhold@gmx.de> 7 */ 8 9 10 #include "Package.h" 11 12 #include <fcntl.h> 13 14 #include <File.h> 15 16 #include <AutoDeleter.h> 17 18 #include "DebugSupport.h" 19 20 21 Package::Package() 22 : 23 fNodeRef(), 24 fFileName(), 25 fInfo(), 26 fActive(false), 27 fFileNameHashTableNext(NULL), 28 fNodeRefHashTableNext(NULL), 29 fIgnoreEntryCreated(0), 30 fIgnoreEntryRemoved(0) 31 { 32 } 33 34 35 Package::~Package() 36 { 37 } 38 39 40 status_t 41 Package::Init(const entry_ref& entryRef) 42 { 43 // init the file name 44 fFileName = entryRef.name; 45 if (fFileName.IsEmpty()) 46 RETURN_ERROR(B_NO_MEMORY); 47 48 // open the file and get the node_ref 49 BFile file; 50 status_t error = file.SetTo(&entryRef, B_READ_ONLY); 51 if (error != B_OK) 52 RETURN_ERROR(error); 53 54 error = file.GetNodeRef(&fNodeRef); 55 if (error != B_OK) 56 RETURN_ERROR(error); 57 58 // get the package info 59 int fd = file.Dup(); 60 if (fd < 0) 61 RETURN_ERROR(error); 62 FileDescriptorCloser fdCloser(fd); 63 64 error = fInfo.ReadFromPackageFile(fd); 65 if (error != B_OK) 66 RETURN_ERROR(error); 67 68 if (fFileName != fInfo.CanonicalFileName()) 69 fInfo.SetFileName(fFileName); 70 71 return B_OK; 72 } 73 74 75 BString 76 Package::RevisionedName() const 77 { 78 return BString().SetToFormat("%s-%s", fInfo.Name().String(), 79 fInfo.Version().ToString().String()); 80 } 81 82 83 BString 84 Package::RevisionedNameThrows() const 85 { 86 BString result(RevisionedName()); 87 if (result.IsEmpty()) 88 throw std::bad_alloc(); 89 return result; 90 } 91