2 * dpkg-split - splitting and joining of multipart *.deb archives
5 * Copyright © 1995 Ian Jackson <ijackson@chiark.greenend.org.uk>
7 * This is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
31 #include <dpkg/i18n.h>
32 #include <dpkg/dpkg.h>
33 #include <dpkg/dpkg-db.h>
34 #include <dpkg/buffer.h>
35 #include <dpkg/options.h>
37 #include "dpkg-split.h"
39 void reassemble(struct partinfo
**partlist
, const char *outputfile
) {
40 struct dpkg_error err
;
44 printf(P_("Putting package %s together from %d part: ",
45 "Putting package %s together from %d parts: ",
46 partlist
[0]->maxpartn
),
47 partlist
[0]->package
,partlist
[0]->maxpartn
);
49 fd_out
= creat(outputfile
, 0644);
51 ohshite(_("unable to open output file '%.250s'"), outputfile
);
52 for (i
=0; i
<partlist
[0]->maxpartn
; i
++) {
53 struct partinfo
*pi
= partlist
[i
];
56 fd_in
= open(pi
->filename
, O_RDONLY
);
58 ohshite(_("unable to (re)open input part file '%.250s'"), pi
->filename
);
59 if (fd_skip(fd_in
, pi
->headerlen
, &err
) < 0)
60 ohshit(_("cannot skip split package header for '%s': %s"), pi
->filename
,
62 if (fd_fd_copy(fd_in
, fd_out
, pi
->thispartlen
, &err
) < 0)
63 ohshit(_("cannot append split package part '%s' to '%s': %s"),
64 pi
->filename
, outputfile
, err
.str
);
70 ohshite(_("unable to sync file '%s'"), outputfile
);
72 ohshite(_("unable to close file '%s'"), outputfile
);
78 void addtopartlist(struct partinfo
**partlist
,
79 struct partinfo
*pi
, struct partinfo
*refi
) {
82 if (strcmp(pi
->package
,refi
->package
) ||
83 strcmp(pi
->version
,refi
->version
) ||
84 strcmp(pi
->md5sum
,refi
->md5sum
) ||
85 pi
->orglength
!= refi
->orglength
||
86 pi
->maxpartn
!= refi
->maxpartn
||
87 pi
->maxpartlen
!= refi
->maxpartlen
) {
90 ohshit(_("files '%.250s' and '%.250s' are not parts of the same file"),
91 pi
->filename
,refi
->filename
);
95 ohshit(_("there are several versions of part %d - at least '%.250s' and '%.250s'"),
96 pi
->thispartn
, pi
->filename
, partlist
[i
]->filename
);
101 do_join(const char *const *argv
)
104 struct partqueue
*queue
= NULL
;
105 struct partqueue
*pq
;
106 struct partinfo
*refi
, **partlist
;
110 badusage(_("--%s requires one or more part file arguments"),
112 while ((thisarg
= *argv
++)) {
113 pq
= nfmalloc(sizeof(*pq
));
115 mustgetpartinfo(thisarg
,&pq
->info
);
117 pq
->nextinqueue
= queue
;
121 for (pq
= queue
; pq
; pq
= pq
->nextinqueue
)
122 if (!refi
|| pq
->info
.thispartn
< refi
->thispartn
) refi
= &pq
->info
;
124 internerr("empty deb part queue");
126 partlist
= nfmalloc(sizeof(*partlist
) * refi
->maxpartn
);
127 for (i
= 0; i
< refi
->maxpartn
; i
++)
129 for (pq
= queue
; pq
; pq
= pq
->nextinqueue
) {
130 struct partinfo
*pi
= &pq
->info
;
132 addtopartlist(partlist
,pi
,refi
);
134 for (i
=0; i
<refi
->maxpartn
; i
++) {
135 if (!partlist
[i
]) ohshit(_("part %d is missing"),i
+1);
137 if (!opt_outputfile
) {
140 p
= nfmalloc(strlen(refi
->package
)+1+strlen(refi
->version
)+sizeof(DEBEXT
));
141 strcpy(p
,refi
->package
);
143 strcat(p
,refi
->version
);
145 strcat(p
, refi
->arch
? refi
->arch
: "unknown");
149 reassemble(partlist
, opt_outputfile
);