Skip to content

Follow file symlinks too #2827

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/src/io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,7 @@ ByteStream createTarGz(List<String> contents, {String baseDir}) {
// ustar is the most recent tar format that's compatible across all
// OSes.
'--format=ustar',
'--dereference',
'--create',
'--gzip',
'--directory',
Expand Down
76 changes: 76 additions & 0 deletions test/lish/follow_dir_symlink_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'dart:convert';
import 'dart:io';
import 'dart:math' as math;
import 'dart:typed_data';

import 'package:path/path.dart' as p;
import 'package:shelf/shelf.dart' as shelf;
import 'package:test/test.dart';

import 'package:pub/src/exit_codes.dart' as exit_codes;

import '../descriptor.dart' as d;
import '../test_pub.dart';
import 'utils.dart';

void main() {
// Symlinks are not followed on Windows,
// because 7-Zip does not provide such an option.
if (Platform.isWindows) return;

test('publish follows directory symlinks', () async {
await d.validPackage.create();

var appRoot = p.join(d.sandbox, appPath);

// hidden directory, so it is excluded
const target = '.target';
Directory(p.join(appRoot, target)).createSync();

// non-hidden file in the directory
final file = p.join(target, 'file');
final data = Uint8List(1 << 20); // 1 MiB
final rng = math.Random();
data.setAll(0, Iterable.generate(data.length, (i) => rng.nextInt(256)));
File(p.join(appRoot, file)).writeAsBytesSync(data);

// non-hidden link that points to the target directory
const link = 'link';
Link(p.join(appRoot, link)).createSync(target);

await servePackages();
await d.credentialsFile(globalPackageServer, 'access token').create();
var pub = await startPublish(globalPackageServer);

await confirmPublish(pub);
handleUploadForm(globalPackageServer);

var packageSize = 0;

globalPackageServer.expect('POST', '/upload', (request) {
return request
.read()
.fold(0, (size, bytes) => size + bytes.length)
.then((size) => packageSize = size)
.then((_) => globalPackageServer.url)
.then((url) => shelf.Response.found(Uri.parse(url).resolve('/create')));
});

globalPackageServer.expect('GET', '/create', (request) {
return shelf.Response.ok(jsonEncode({
'success': {'message': 'Package test_pkg 1.0.0 uploaded!'}
}));
});

expect(pub.stdout, emits(startsWith('Uploading...')));
expect(pub.stdout, emits('Package test_pkg 1.0.0 uploaded!'));
await pub.shouldExit(exit_codes.SUCCESS);

// if the link has been followed, the body contains the random data
expect(packageSize, greaterThan(data.length));
});
}
72 changes: 72 additions & 0 deletions test/lish/follow_file_symlink_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'dart:convert';
import 'dart:io';
import 'dart:math' as math;
import 'dart:typed_data';

import 'package:path/path.dart' as p;
import 'package:shelf/shelf.dart' as shelf;
import 'package:test/test.dart';

import 'package:pub/src/exit_codes.dart' as exit_codes;

import '../descriptor.dart' as d;
import '../test_pub.dart';
import 'utils.dart';

void main() {
// Symlinks are not followed on Windows,
// because 7-Zip does not provide such an option.
if (Platform.isWindows) return;

test('publish follows file symlinks', () async {
await d.validPackage.create();

var appRoot = p.join(d.sandbox, appPath);

// hidden target file, so it is excluded
const target = '.target';
final data = Uint8List(1 << 20); // 1 MiB
final rng = math.Random();
data.setAll(0, Iterable.generate(data.length, (i) => rng.nextInt(256)));
File(p.join(appRoot, target)).writeAsBytesSync(data);

// non-hidden link that points to the target file
const link = 'link';
Link(p.join(appRoot, link)).createSync(target);

await servePackages();
await d.credentialsFile(globalPackageServer, 'access token').create();
var pub = await startPublish(globalPackageServer);

await confirmPublish(pub);
handleUploadForm(globalPackageServer);

var packageSize = 0;

globalPackageServer.expect('POST', '/upload', (request) {
return request
.read()
.fold(0, (size, bytes) => size + bytes.length)
.then((size) => packageSize = size)
.then((_) => globalPackageServer.url)
.then((url) => shelf.Response.found(Uri.parse(url).resolve('/create')));
});

globalPackageServer.expect('GET', '/create', (request) {
return shelf.Response.ok(jsonEncode({
'success': {'message': 'Package test_pkg 1.0.0 uploaded!'}
}));
});

expect(pub.stdout, emits(startsWith('Uploading...')));
expect(pub.stdout, emits('Package test_pkg 1.0.0 uploaded!'));
await pub.shouldExit(exit_codes.SUCCESS);

// if the link has been followed, the body contains the random data
expect(packageSize, greaterThan(data.length));
});
}