1// Copyright 2017 Google Inc. All rights reserved. 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15package main 16 17import ( 18 "errors" 19 "flag" 20 "fmt" 21 "hash/crc32" 22 "io" 23 "io/ioutil" 24 "log" 25 "os" 26 "path/filepath" 27 "sort" 28 "strings" 29 30 "android/soong/response" 31 32 "github.com/google/blueprint/pathtools" 33 34 "android/soong/jar" 35 "android/soong/third_party/zip" 36) 37 38// Input zip: we can open it, close it, and obtain an array of entries 39type InputZip interface { 40 Name() string 41 Open() error 42 Close() error 43 Entries() []*zip.File 44 IsOpen() bool 45} 46 47// An entry that can be written to the output zip 48type ZipEntryContents interface { 49 String() string 50 IsDir() bool 51 CRC32() uint32 52 Size() uint64 53 WriteToZip(dest string, zw *zip.Writer) error 54} 55 56// a ZipEntryFromZip is a ZipEntryContents that pulls its content from another zip 57// identified by the input zip and the index of the entry in its entries array 58type ZipEntryFromZip struct { 59 inputZip InputZip 60 index int 61 name string 62 isDir bool 63 crc32 uint32 64 size uint64 65} 66 67func NewZipEntryFromZip(inputZip InputZip, entryIndex int) *ZipEntryFromZip { 68 fi := inputZip.Entries()[entryIndex] 69 newEntry := ZipEntryFromZip{inputZip: inputZip, 70 index: entryIndex, 71 name: fi.Name, 72 isDir: fi.FileInfo().IsDir(), 73 crc32: fi.CRC32, 74 size: fi.UncompressedSize64, 75 } 76 return &newEntry 77} 78 79func (ze ZipEntryFromZip) String() string { 80 return fmt.Sprintf("%s!%s", ze.inputZip.Name(), ze.name) 81} 82 83func (ze ZipEntryFromZip) IsDir() bool { 84 return ze.isDir 85} 86 87func (ze ZipEntryFromZip) CRC32() uint32 { 88 return ze.crc32 89} 90 91func (ze ZipEntryFromZip) Size() uint64 { 92 return ze.size 93} 94 95func (ze ZipEntryFromZip) WriteToZip(dest string, zw *zip.Writer) error { 96 if err := ze.inputZip.Open(); err != nil { 97 return err 98 } 99 return zw.CopyFrom(ze.inputZip.Entries()[ze.index], dest) 100} 101 102// a ZipEntryFromBuffer is a ZipEntryContents that pulls its content from a []byte 103type ZipEntryFromBuffer struct { 104 fh *zip.FileHeader 105 content []byte 106} 107 108func (be ZipEntryFromBuffer) String() string { 109 return "internal buffer" 110} 111 112func (be ZipEntryFromBuffer) IsDir() bool { 113 return be.fh.FileInfo().IsDir() 114} 115 116func (be ZipEntryFromBuffer) CRC32() uint32 { 117 return crc32.ChecksumIEEE(be.content) 118} 119 120func (be ZipEntryFromBuffer) Size() uint64 { 121 return uint64(len(be.content)) 122} 123 124func (be ZipEntryFromBuffer) WriteToZip(dest string, zw *zip.Writer) error { 125 w, err := zw.CreateHeader(be.fh) 126 if err != nil { 127 return err 128 } 129 130 if !be.IsDir() { 131 _, err = w.Write(be.content) 132 if err != nil { 133 return err 134 } 135 } 136 137 return nil 138} 139 140// Processing state. 141type OutputZip struct { 142 outputWriter *zip.Writer 143 stripDirEntries bool 144 emulateJar bool 145 sortEntries bool 146 ignoreDuplicates bool 147 excludeDirs []string 148 excludeFiles []string 149 sourceByDest map[string]ZipEntryContents 150} 151 152func NewOutputZip(outputWriter *zip.Writer, sortEntries, emulateJar, stripDirEntries, ignoreDuplicates bool) *OutputZip { 153 return &OutputZip{ 154 outputWriter: outputWriter, 155 stripDirEntries: stripDirEntries, 156 emulateJar: emulateJar, 157 sortEntries: sortEntries, 158 sourceByDest: make(map[string]ZipEntryContents, 0), 159 ignoreDuplicates: ignoreDuplicates, 160 } 161} 162 163func (oz *OutputZip) setExcludeDirs(excludeDirs []string) { 164 oz.excludeDirs = make([]string, len(excludeDirs)) 165 for i, dir := range excludeDirs { 166 oz.excludeDirs[i] = filepath.Clean(dir) 167 } 168} 169 170func (oz *OutputZip) setExcludeFiles(excludeFiles []string) { 171 oz.excludeFiles = excludeFiles 172} 173 174// Adds an entry with given name whose source is given ZipEntryContents. Returns old ZipEntryContents 175// if entry with given name already exists. 176func (oz *OutputZip) addZipEntry(name string, source ZipEntryContents) (ZipEntryContents, error) { 177 if existingSource, exists := oz.sourceByDest[name]; exists { 178 return existingSource, nil 179 } 180 oz.sourceByDest[name] = source 181 // Delay writing an entry if entries need to be rearranged. 182 if oz.emulateJar || oz.sortEntries { 183 return nil, nil 184 } 185 return nil, source.WriteToZip(name, oz.outputWriter) 186} 187 188// Adds an entry for the manifest (META-INF/MANIFEST.MF from the given file 189func (oz *OutputZip) addManifest(manifestPath string) error { 190 if !oz.stripDirEntries { 191 if _, err := oz.addZipEntry(jar.MetaDir, ZipEntryFromBuffer{jar.MetaDirFileHeader(), nil}); err != nil { 192 return err 193 } 194 } 195 contents, err := ioutil.ReadFile(manifestPath) 196 if err == nil { 197 fh, buf, err := jar.ManifestFileContents(contents) 198 if err == nil { 199 _, err = oz.addZipEntry(jar.ManifestFile, ZipEntryFromBuffer{fh, buf}) 200 } 201 } 202 return err 203} 204 205// Adds an entry with given name and contents read from given file 206func (oz *OutputZip) addZipEntryFromFile(name string, path string) error { 207 buf, err := ioutil.ReadFile(path) 208 if err == nil { 209 fh := &zip.FileHeader{ 210 Name: name, 211 Method: zip.Store, 212 UncompressedSize64: uint64(len(buf)), 213 } 214 fh.SetMode(0700) 215 fh.SetModTime(jar.DefaultTime) 216 _, err = oz.addZipEntry(name, ZipEntryFromBuffer{fh, buf}) 217 } 218 return err 219} 220 221func (oz *OutputZip) addEmptyEntry(entry string) error { 222 var emptyBuf []byte 223 fh := &zip.FileHeader{ 224 Name: entry, 225 Method: zip.Store, 226 UncompressedSize64: uint64(len(emptyBuf)), 227 } 228 fh.SetMode(0700) 229 fh.SetModTime(jar.DefaultTime) 230 _, err := oz.addZipEntry(entry, ZipEntryFromBuffer{fh, emptyBuf}) 231 return err 232} 233 234// Returns true if given entry is to be excluded 235func (oz *OutputZip) isEntryExcluded(name string) bool { 236 for _, dir := range oz.excludeDirs { 237 dir = filepath.Clean(dir) 238 patterns := []string{ 239 dir + "/", // the directory itself 240 dir + "/**/*", // files recursively in the directory 241 dir + "/**/*/", // directories recursively in the directory 242 } 243 244 for _, pattern := range patterns { 245 match, err := pathtools.Match(pattern, name) 246 if err != nil { 247 panic(fmt.Errorf("%s: %s", err.Error(), pattern)) 248 } 249 if match { 250 if oz.emulateJar { 251 // When merging jar files, don't strip META-INF/MANIFEST.MF even if stripping META-INF is 252 // requested. 253 // TODO(ccross): which files does this affect? 254 if name != jar.MetaDir && name != jar.ManifestFile { 255 return true 256 } 257 } 258 return true 259 } 260 } 261 } 262 263 for _, pattern := range oz.excludeFiles { 264 match, err := pathtools.Match(pattern, name) 265 if err != nil { 266 panic(fmt.Errorf("%s: %s", err.Error(), pattern)) 267 } 268 if match { 269 return true 270 } 271 } 272 return false 273} 274 275// Creates a zip entry whose contents is an entry from the given input zip. 276func (oz *OutputZip) copyEntry(inputZip InputZip, index int) error { 277 entry := NewZipEntryFromZip(inputZip, index) 278 if oz.stripDirEntries && entry.IsDir() { 279 return nil 280 } 281 existingEntry, err := oz.addZipEntry(entry.name, entry) 282 if err != nil { 283 return err 284 } 285 if existingEntry == nil { 286 return nil 287 } 288 289 // File types should match 290 if existingEntry.IsDir() != entry.IsDir() { 291 return fmt.Errorf("Directory/file mismatch at %v from %v and %v\n", 292 entry.name, existingEntry, entry) 293 } 294 295 if oz.ignoreDuplicates || 296 // Skip manifest and module info files that are not from the first input file 297 (oz.emulateJar && entry.name == jar.ManifestFile || entry.name == jar.ModuleInfoClass) || 298 // Identical entries 299 (existingEntry.CRC32() == entry.CRC32() && existingEntry.Size() == entry.Size()) || 300 // Directory entries 301 entry.IsDir() { 302 return nil 303 } 304 305 return fmt.Errorf("Duplicate path %v found in %v and %v\n", entry.name, existingEntry, inputZip.Name()) 306} 307 308func (oz *OutputZip) entriesArray() []string { 309 entries := make([]string, len(oz.sourceByDest)) 310 i := 0 311 for entry := range oz.sourceByDest { 312 entries[i] = entry 313 i++ 314 } 315 return entries 316} 317 318func (oz *OutputZip) jarSorted() []string { 319 entries := oz.entriesArray() 320 sort.SliceStable(entries, func(i, j int) bool { return jar.EntryNamesLess(entries[i], entries[j]) }) 321 return entries 322} 323 324func (oz *OutputZip) alphanumericSorted() []string { 325 entries := oz.entriesArray() 326 sort.Strings(entries) 327 return entries 328} 329 330func (oz *OutputZip) writeEntries(entries []string) error { 331 for _, entry := range entries { 332 source, _ := oz.sourceByDest[entry] 333 if err := source.WriteToZip(entry, oz.outputWriter); err != nil { 334 return err 335 } 336 } 337 return nil 338} 339 340func (oz *OutputZip) getUninitializedPythonPackages(inputZips []InputZip) ([]string, error) { 341 // the runfiles packages needs to be populated with "__init__.py". 342 // the runfiles dirs have been treated as packages. 343 allPackages := make(map[string]bool) 344 initedPackages := make(map[string]bool) 345 getPackage := func(path string) string { 346 ret := filepath.Dir(path) 347 // filepath.Dir("abc") -> "." and filepath.Dir("/abc") -> "/". 348 if ret == "." || ret == "/" { 349 return "" 350 } 351 return ret 352 } 353 354 // put existing __init__.py files to a set first. This set is used for preventing 355 // generated __init__.py files from overwriting existing ones. 356 for _, inputZip := range inputZips { 357 if err := inputZip.Open(); err != nil { 358 return nil, err 359 } 360 for _, file := range inputZip.Entries() { 361 pyPkg := getPackage(file.Name) 362 if filepath.Base(file.Name) == "__init__.py" { 363 if _, found := initedPackages[pyPkg]; found { 364 panic(fmt.Errorf("found __init__.py path duplicates during pars merging: %q", file.Name)) 365 } 366 initedPackages[pyPkg] = true 367 } 368 for pyPkg != "" { 369 if _, found := allPackages[pyPkg]; found { 370 break 371 } 372 allPackages[pyPkg] = true 373 pyPkg = getPackage(pyPkg) 374 } 375 } 376 } 377 noInitPackages := make([]string, 0) 378 for pyPkg := range allPackages { 379 if _, found := initedPackages[pyPkg]; !found { 380 noInitPackages = append(noInitPackages, pyPkg) 381 } 382 } 383 return noInitPackages, nil 384} 385 386// An InputZip owned by the InputZipsManager. Opened ManagedInputZip's are chained in the open order. 387type ManagedInputZip struct { 388 owner *InputZipsManager 389 realInputZip InputZip 390 older *ManagedInputZip 391 newer *ManagedInputZip 392} 393 394// Maintains the array of ManagedInputZips, keeping track of open input ones. When an InputZip is opened, 395// may close some other InputZip to limit the number of open ones. 396type InputZipsManager struct { 397 inputZips []*ManagedInputZip 398 nOpenZips int 399 maxOpenZips int 400 openInputZips *ManagedInputZip 401} 402 403func (miz *ManagedInputZip) unlink() { 404 olderMiz := miz.older 405 newerMiz := miz.newer 406 if newerMiz.older != miz || olderMiz.newer != miz { 407 panic(fmt.Errorf("removing %p:%#v: broken list between %p:%#v and %p:%#v", 408 miz, miz, newerMiz, newerMiz, olderMiz, olderMiz)) 409 } 410 olderMiz.newer = newerMiz 411 newerMiz.older = olderMiz 412 miz.newer = nil 413 miz.older = nil 414} 415 416func (miz *ManagedInputZip) link(olderMiz *ManagedInputZip) { 417 if olderMiz.newer != nil || olderMiz.older != nil { 418 panic(fmt.Errorf("inputZip is already open")) 419 } 420 oldOlderMiz := miz.older 421 if oldOlderMiz.newer != miz { 422 panic(fmt.Errorf("broken list between %p:%#v and %p:%#v", miz, miz, oldOlderMiz, oldOlderMiz)) 423 } 424 miz.older = olderMiz 425 olderMiz.older = oldOlderMiz 426 oldOlderMiz.newer = olderMiz 427 olderMiz.newer = miz 428} 429 430func NewInputZipsManager(nInputZips, maxOpenZips int) *InputZipsManager { 431 if maxOpenZips < 3 { 432 panic(fmt.Errorf("open zips limit should be above 3")) 433 } 434 // In the fake element .older points to the most recently opened InputZip, and .newer points to the oldest. 435 head := new(ManagedInputZip) 436 head.older = head 437 head.newer = head 438 return &InputZipsManager{ 439 inputZips: make([]*ManagedInputZip, 0, nInputZips), 440 maxOpenZips: maxOpenZips, 441 openInputZips: head, 442 } 443} 444 445// InputZip factory 446func (izm *InputZipsManager) Manage(inz InputZip) InputZip { 447 iz := &ManagedInputZip{owner: izm, realInputZip: inz} 448 izm.inputZips = append(izm.inputZips, iz) 449 return iz 450} 451 452// Opens or reopens ManagedInputZip. 453func (izm *InputZipsManager) reopen(miz *ManagedInputZip) error { 454 if miz.realInputZip.IsOpen() { 455 if miz != izm.openInputZips { 456 miz.unlink() 457 izm.openInputZips.link(miz) 458 } 459 return nil 460 } 461 if izm.nOpenZips >= izm.maxOpenZips { 462 if err := izm.close(izm.openInputZips.older); err != nil { 463 return err 464 } 465 } 466 if err := miz.realInputZip.Open(); err != nil { 467 return err 468 } 469 izm.openInputZips.link(miz) 470 izm.nOpenZips++ 471 return nil 472} 473 474func (izm *InputZipsManager) close(miz *ManagedInputZip) error { 475 if miz.IsOpen() { 476 err := miz.realInputZip.Close() 477 izm.nOpenZips-- 478 miz.unlink() 479 return err 480 } 481 return nil 482} 483 484// Checks that openInputZips deque is valid 485func (izm *InputZipsManager) checkOpenZipsDeque() { 486 nReallyOpen := 0 487 el := izm.openInputZips 488 for { 489 elNext := el.older 490 if elNext.newer != el { 491 panic(fmt.Errorf("Element:\n %p: %v\nNext:\n %p %v", el, el, elNext, elNext)) 492 } 493 if elNext == izm.openInputZips { 494 break 495 } 496 el = elNext 497 if !el.IsOpen() { 498 panic(fmt.Errorf("Found unopened element")) 499 } 500 nReallyOpen++ 501 if nReallyOpen > izm.nOpenZips { 502 panic(fmt.Errorf("found %d open zips, should be %d", nReallyOpen, izm.nOpenZips)) 503 } 504 } 505 if nReallyOpen > izm.nOpenZips { 506 panic(fmt.Errorf("found %d open zips, should be %d", nReallyOpen, izm.nOpenZips)) 507 } 508} 509 510func (miz *ManagedInputZip) Name() string { 511 return miz.realInputZip.Name() 512} 513 514func (miz *ManagedInputZip) Open() error { 515 return miz.owner.reopen(miz) 516} 517 518func (miz *ManagedInputZip) Close() error { 519 return miz.owner.close(miz) 520} 521 522func (miz *ManagedInputZip) IsOpen() bool { 523 return miz.realInputZip.IsOpen() 524} 525 526func (miz *ManagedInputZip) Entries() []*zip.File { 527 if !miz.IsOpen() { 528 panic(fmt.Errorf("%s: is not open", miz.Name())) 529 } 530 return miz.realInputZip.Entries() 531} 532 533// Actual processing. 534func mergeZips(inputZips []InputZip, writer *zip.Writer, manifest, pyMain string, 535 sortEntries, emulateJar, emulatePar, stripDirEntries, ignoreDuplicates bool, 536 excludeFiles, excludeDirs []string, zipsToNotStrip map[string]bool) error { 537 538 out := NewOutputZip(writer, sortEntries, emulateJar, stripDirEntries, ignoreDuplicates) 539 out.setExcludeFiles(excludeFiles) 540 out.setExcludeDirs(excludeDirs) 541 if manifest != "" { 542 if err := out.addManifest(manifest); err != nil { 543 return err 544 } 545 } 546 if pyMain != "" { 547 if err := out.addZipEntryFromFile("__main__.py", pyMain); err != nil { 548 return err 549 } 550 } 551 552 if emulatePar { 553 noInitPackages, err := out.getUninitializedPythonPackages(inputZips) 554 if err != nil { 555 return err 556 } 557 for _, uninitializedPyPackage := range noInitPackages { 558 if err = out.addEmptyEntry(filepath.Join(uninitializedPyPackage, "__init__.py")); err != nil { 559 return err 560 } 561 } 562 } 563 564 // Finally, add entries from all the input zips. 565 for _, inputZip := range inputZips { 566 _, copyFully := zipsToNotStrip[inputZip.Name()] 567 if err := inputZip.Open(); err != nil { 568 return err 569 } 570 571 for i, entry := range inputZip.Entries() { 572 if copyFully || !out.isEntryExcluded(entry.Name) { 573 if err := out.copyEntry(inputZip, i); err != nil { 574 return err 575 } 576 } 577 } 578 // Unless we need to rearrange the entries, the input zip can now be closed. 579 if !(emulateJar || sortEntries) { 580 if err := inputZip.Close(); err != nil { 581 return err 582 } 583 } 584 } 585 586 if emulateJar { 587 return out.writeEntries(out.jarSorted()) 588 } else if sortEntries { 589 return out.writeEntries(out.alphanumericSorted()) 590 } 591 return nil 592} 593 594// Process command line 595type fileList []string 596 597func (f *fileList) String() string { 598 return `""` 599} 600 601func (f *fileList) Set(name string) error { 602 *f = append(*f, filepath.Clean(name)) 603 604 return nil 605} 606 607type zipsToNotStripSet map[string]bool 608 609func (s zipsToNotStripSet) String() string { 610 return `""` 611} 612 613func (s zipsToNotStripSet) Set(path string) error { 614 s[path] = true 615 return nil 616} 617 618var ( 619 sortEntries = flag.Bool("s", false, "sort entries (defaults to the order from the input zip files)") 620 emulateJar = flag.Bool("j", false, "sort zip entries using jar ordering (META-INF first)") 621 emulatePar = flag.Bool("p", false, "merge zip entries based on par format") 622 excludeDirs fileList 623 excludeFiles fileList 624 zipsToNotStrip = make(zipsToNotStripSet) 625 stripDirEntries = flag.Bool("D", false, "strip directory entries from the output zip file") 626 manifest = flag.String("m", "", "manifest file to insert in jar") 627 pyMain = flag.String("pm", "", "__main__.py file to insert in par") 628 prefix = flag.String("prefix", "", "A file to prefix to the zip file") 629 ignoreDuplicates = flag.Bool("ignore-duplicates", false, "take each entry from the first zip it exists in and don't warn") 630) 631 632func init() { 633 flag.Var(&excludeDirs, "stripDir", "directories to be excluded from the output zip, accepts wildcards") 634 flag.Var(&excludeFiles, "stripFile", "files to be excluded from the output zip, accepts wildcards") 635 flag.Var(&zipsToNotStrip, "zipToNotStrip", "the input zip file which is not applicable for stripping") 636} 637 638type FileInputZip struct { 639 name string 640 reader *zip.ReadCloser 641} 642 643func (fiz *FileInputZip) Name() string { 644 return fiz.name 645} 646 647func (fiz *FileInputZip) Close() error { 648 if fiz.IsOpen() { 649 reader := fiz.reader 650 fiz.reader = nil 651 return reader.Close() 652 } 653 return nil 654} 655 656func (fiz *FileInputZip) Entries() []*zip.File { 657 if !fiz.IsOpen() { 658 panic(fmt.Errorf("%s: is not open", fiz.Name())) 659 } 660 return fiz.reader.File 661} 662 663func (fiz *FileInputZip) IsOpen() bool { 664 return fiz.reader != nil 665} 666 667func (fiz *FileInputZip) Open() error { 668 if fiz.IsOpen() { 669 return nil 670 } 671 var err error 672 if fiz.reader, err = zip.OpenReader(fiz.Name()); err != nil { 673 return fmt.Errorf("%s: %s", fiz.Name(), err.Error()) 674 } 675 return nil 676} 677 678func main() { 679 flag.Usage = func() { 680 fmt.Fprintln(os.Stderr, "usage: merge_zips [-jpsD] [-m manifest] [--prefix script] [-pm __main__.py] OutputZip [inputs...]") 681 flag.PrintDefaults() 682 } 683 684 // parse args 685 flag.Parse() 686 args := flag.Args() 687 if len(args) < 1 { 688 flag.Usage() 689 os.Exit(1) 690 } 691 outputPath := args[0] 692 inputs := make([]string, 0) 693 for _, input := range args[1:] { 694 if input[0] == '@' { 695 f, err := os.Open(strings.TrimPrefix(input[1:], "@")) 696 if err != nil { 697 log.Fatal(err) 698 } 699 700 rspInputs, err := response.ReadRspFile(f) 701 f.Close() 702 if err != nil { 703 log.Fatal(err) 704 } 705 inputs = append(inputs, rspInputs...) 706 } else { 707 inputs = append(inputs, input) 708 } 709 } 710 711 log.SetFlags(log.Lshortfile) 712 713 // make writer 714 outputZip, err := os.Create(outputPath) 715 if err != nil { 716 log.Fatal(err) 717 } 718 defer outputZip.Close() 719 720 var offset int64 721 if *prefix != "" { 722 prefixFile, err := os.Open(*prefix) 723 if err != nil { 724 log.Fatal(err) 725 } 726 offset, err = io.Copy(outputZip, prefixFile) 727 if err != nil { 728 log.Fatal(err) 729 } 730 } 731 732 writer := zip.NewWriter(outputZip) 733 defer func() { 734 err := writer.Close() 735 if err != nil { 736 log.Fatal(err) 737 } 738 }() 739 writer.SetOffset(offset) 740 741 if *manifest != "" && !*emulateJar { 742 log.Fatal(errors.New("must specify -j when specifying a manifest via -m")) 743 } 744 745 if *pyMain != "" && !*emulatePar { 746 log.Fatal(errors.New("must specify -p when specifying a Python __main__.py via -pm")) 747 } 748 749 // do merge 750 inputZipsManager := NewInputZipsManager(len(inputs), 1000) 751 inputZips := make([]InputZip, len(inputs)) 752 for i, input := range inputs { 753 inputZips[i] = inputZipsManager.Manage(&FileInputZip{name: input}) 754 } 755 err = mergeZips(inputZips, writer, *manifest, *pyMain, *sortEntries, *emulateJar, *emulatePar, 756 *stripDirEntries, *ignoreDuplicates, []string(excludeFiles), []string(excludeDirs), 757 map[string]bool(zipsToNotStrip)) 758 if err != nil { 759 log.Fatal(err) 760 } 761} 762