Chromium Code Reviews

Side by Side Diff: sdk/lib/_internal/pub/test/lish/many_files_test.dart

Issue 1013753015: Limit the length of file paths used in many_files_test. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import 'dart:convert'; 5 import 'dart:convert';
6 import 'dart:io'; 6 import 'dart:io';
7 import 'dart:math' as math; 7 import 'dart:math' as math;
8 8
9 import 'package:path/path.dart' as p; 9 import 'package:path/path.dart' as p;
10 import 'package:scheduled_test/scheduled_test.dart'; 10 import 'package:scheduled_test/scheduled_test.dart';
11 import 'package:scheduled_test/scheduled_server.dart'; 11 import 'package:scheduled_test/scheduled_server.dart';
12 import 'package:shelf/shelf.dart' as shelf; 12 import 'package:shelf/shelf.dart' as shelf;
13 13
14 import '../../lib/src/exit_codes.dart' as exit_codes; 14 import '../../lib/src/exit_codes.dart' as exit_codes;
15 import '../descriptor.dart' as d; 15 import '../descriptor.dart' as d;
16 import '../test_pub.dart'; 16 import '../test_pub.dart';
17 import 'utils.dart'; 17 import 'utils.dart';
18 18
19 /// The depth of directories to use when creating files to tickle 19 /// The maximum number of bytes in an entire path.
20 /// argument-length limits.
21 final _depth = 10;
22
23 /// The maximum number of characters in a path component.
24 /// 20 ///
25 /// Only Windows has this tight of a constraint, but we abide by it on all 21 /// This is [Windows's number][MAX_PATH], which is a much tighter constraint
26 /// operating systems to avoid specializing the test too much. 22 /// than OS X or Linux. We use it everywhere for consistency.
27 final _componentMax = 255; 23 ///
24 /// [MAX_PATH]: https://msdn.microsoft.com/en-us/library/windows/desktop/aa38313 0(v=vs.85).aspx
25 const _pathMax = 260;
28 26
29 main() { 27 main() {
30 initConfig(); 28 initConfig();
31 29
32 integration('archives and uploads a package', () { 30 integration('archives and uploads a package with more files than can fit on '
31 'the command line', () {
33 d.validPackage.create(); 32 d.validPackage.create();
34 33
35 var argMax; 34 var argMax;
36 if (Platform.isWindows) { 35 if (Platform.isWindows) {
37 // On Windows, the maximum argument list length is 8^5 bytes. 36 // On Windows, the maximum argument list length is 8^5 bytes.
38 argMax = math.pow(8, 5); 37 argMax = math.pow(8, 5);
39 } else { 38 } else {
40 // On POSIX, the maximum argument list length can be retrieved 39 // On POSIX, the maximum argument list length can be retrieved
41 // automatically. 40 // automatically.
42 var result = Process.runSync("getconf", ["ARG_MAX"]); 41 var result = Process.runSync("getconf", ["ARG_MAX"]);
43 if (result.exitCode != 0) { 42 if (result.exitCode != 0) {
44 fail("getconf failed with exit code ${result.exitCode}:\n" 43 fail("getconf failed with exit code ${result.exitCode}:\n"
45 "${result.stderr}"); 44 "${result.stderr}");
46 } 45 }
47 46
48 argMax = int.parse(result.stdout); 47 argMax = int.parse(result.stdout);
49 } 48 }
50 49
51 schedule(() { 50 schedule(() {
52 var dir = p.join(sandboxDir, appPath); 51 var appRoot = p.join(sandboxDir, appPath);
53 for (var i = 0; i < _depth; i++) {
54 dir = p.join(dir, "x" * _componentMax);
55 new Directory(dir).createSync();
56 }
57 52
58 var pathLength = (_componentMax + 1) * _depth; 53 // We'll make the filenames as long as possible to reduce the number of
59 var filesToCreate = (argMax / pathLength).ceil(); 54 // files we have to create to hit the maximum. However, the tar process
55 // uses relative paths, which means we can't count the root as part of the
56 // length.
57 var lengthPerFile = _pathMax - appRoot.length;
58
59 // Create enough files to hit [argMax]. This may be a slight overestimate,
60 // since other options are passed to the tar command line, but we don't
61 // know how long those will be.
62 var filesToCreate = (argMax / lengthPerFile).ceil();
63
60 for (var i = 0; i < filesToCreate; i++) { 64 for (var i = 0; i < filesToCreate; i++) {
61 var filePath = p.join(dir, "x" * _componentMax);
62 var iString = i.toString(); 65 var iString = i.toString();
63 filePath = filePath.substring(0, filePath.length - iString.length) +
64 iString;
65 66
66 new File(filePath).writeAsStringSync(""); 67 // The file name contains "x"s to make the path hit [_pathMax],
68 // followed by a number to distinguish different files.
69 var fileName =
70 "x" * (_pathMax - appRoot.length - iString.length - 1) + iString;
71
72 new File(p.join(appRoot, fileName)).writeAsStringSync("");
67 } 73 }
68 }); 74 });
69 75
70 var server = new ScheduledServer(); 76 var server = new ScheduledServer();
71 d.credentialsFile(server, 'access token').create(); 77 d.credentialsFile(server, 'access token').create();
72 var pub = startPublish(server); 78 var pub = startPublish(server);
73 79
74 confirmPublish(pub); 80 confirmPublish(pub);
75 handleUploadForm(server); 81 handleUploadForm(server);
76 handleUpload(server); 82 handleUpload(server);
77 83
78 server.handle('GET', '/create', (request) { 84 server.handle('GET', '/create', (request) {
79 return new shelf.Response.ok(JSON.encode({ 85 return new shelf.Response.ok(JSON.encode({
80 'success': {'message': 'Package test_pkg 1.0.0 uploaded!'} 86 'success': {'message': 'Package test_pkg 1.0.0 uploaded!'}
81 })); 87 }));
82 }); 88 });
83 89
84 pub.stdout.expect(startsWith('Uploading...')); 90 pub.stdout.expect(startsWith('Uploading...'));
85 pub.stdout.expect('Package test_pkg 1.0.0 uploaded!'); 91 pub.stdout.expect('Package test_pkg 1.0.0 uploaded!');
86 pub.shouldExit(exit_codes.SUCCESS); 92 pub.shouldExit(exit_codes.SUCCESS);
87 }); 93 });
88 } 94 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine