File: sources.cc

package info (click to toggle)
apt 3.1.12
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 22,736 kB
  • sloc: cpp: 71,048; sh: 31,750; xml: 5,553; perl: 217; python: 197; ansic: 191; makefile: 41
file content (63 lines) | stat: -rw-r--r-- 1,371 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <config.h>

#include <sstream>
#include <string>

#include <array>
#include <cstring>

#include <apt-pkg/error.h>
#include <apt-pkg/fileutl.h>
#include <apt-pkg/gpgv.h>

#include "sources.h"

bool DscExtract::TakeDsc(const void *newData, unsigned long long newSize)
{
   if (newSize == 0)
   {
      // adding two newlines 'off record' for pkgTagSection.Scan() calls
      Data = "\n\n";
      Length = 0;
      return true;
   }

   Data = std::string((const char*)newData, newSize);
   // adding two newlines 'off record' for pkgTagSection.Scan() calls
   Data.append("\n\n");
   Length = newSize;

   return true;
}

bool DscExtract::Read(std::string FileName)
{
   Data.clear();
   Length = 0;

   FileFd F;
   if (OpenMaybeClearSignedFile(FileName, F) == false)
      return false;

   IsClearSigned = (FileName != F.Name());

   std::ostringstream data;
   std::array<char, APT_BUFFER_SIZE> buffer;
   do {
      unsigned long long actual = 0;
      if (F.Read(buffer.data(), buffer.size()-1, &actual) == false)
	 return _error->Errno("read", "Failed to read dsc file %s", FileName.c_str());
      if (actual == 0)
	 break;
      Length += actual;
      buffer[actual] = '\0';
      data << buffer.data();
   } while(true);

   // adding two newlines 'off record' for pkgTagSection.Scan() calls
   data << "\n\n";
   Data = data.str();
   return true;
}