Skip to content

Various Windows fixes #2001

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

Merged
merged 1 commit into from
Jan 28, 2019
Merged
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
6 changes: 6 additions & 0 deletions build_daemon/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 0.2.1

- Resolve issues with running on Windows.
- Close the lock file prior to deleting it.
- Properly join paths and escape the workspace.

## 0.2.0

- Support custom build results.
Expand Down
21 changes: 13 additions & 8 deletions build_daemon/lib/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,38 @@
// BSD-style license that can be found in the LICENSE file.

import 'dart:io';
import 'package:path/path.dart' as p;

const readyToConnectLog = 'READY TO CONNECT';
const versionSkew = 'DIFFERENT RUNNING VERSION';
const optionsSkew = 'DIFFERENT OPTIONS';

// TODO(grouma) - use pubspec version when this is open sourced.
const currentVersion = '3.0.0';
const currentVersion = '4.0.0';

var _username = Platform.environment['USER'] ?? '';
String daemonWorkspace(String workingDirectory) {
var prefix = '${Directory.systemTemp.path}';
if (_username.isNotEmpty) prefix += '/$_username';
return '$prefix/dart_build_daemon/${workingDirectory.replaceAll("/", "_")}';
var segments = [Directory.systemTemp.path];
if (_username.isNotEmpty) segments.add(_username);
segments.add(workingDirectory
.replaceAll('/', '_')
.replaceAll(':', '_')
.replaceAll('\\', '_'));
return p.joinAll(segments);
}

/// Used to ensure that only one instance of this daemon is running at a time.
String lockFilePath(String workingDirectory) =>
'${daemonWorkspace(workingDirectory)}/.dart_build_lock';
p.join(daemonWorkspace(workingDirectory), '.dart_build_lock');

/// Used to signal to clients on what port the running daemon is listening.
String portFilePath(String workingDirectory) =>
'${daemonWorkspace(workingDirectory)}/.dart_build_daemon_port';
p.join(daemonWorkspace(workingDirectory), '.dart_build_daemon_port');

/// Used to signal to clients the current version of the build daemon.
String versionFilePath(String workingDirectory) =>
'${daemonWorkspace(workingDirectory)}/.dart_build_daemon_version';
p.join(daemonWorkspace(workingDirectory), '.dart_build_daemon_version');

/// Used to signal to clients the current set of options of the build daemon.
String optionsFilePath(String workingDirectory) =>
'${daemonWorkspace(workingDirectory)}/.dart_build_daemon_options';
p.join(daemonWorkspace(workingDirectory), '.dart_build_daemon_options');
9 changes: 6 additions & 3 deletions build_daemon/lib/src/daemon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class Daemon {

Server _server;
StreamSubscription _sub;
RandomAccessFile _lock;

Daemon(this._workingDirectory);

Expand Down Expand Up @@ -67,9 +68,9 @@ class Daemon {
bool tryGetLock() {
try {
_createDaemonWorkspace();
File(lockFilePath(_workingDirectory))
.openSync(mode: FileMode.write)
.lockSync();
_lock =
File(lockFilePath(_workingDirectory)).openSync(mode: FileMode.write);
_lock.lockSync();
return true;
} on FileSystemException {
return false;
Expand All @@ -79,6 +80,8 @@ class Daemon {
Future<void> _cleanUp() async {
await _server?.stop();
await _sub?.cancel();
// We need to close the lock prior to deleting the file.
_lock?.closeSync();
var workspace = Directory(daemonWorkspace(_workingDirectory));
if (workspace.existsSync()) {
workspace.deleteSync(recursive: true);
Expand Down
2 changes: 1 addition & 1 deletion build_daemon/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: build_daemon
version: 0.2.0
version: 0.2.1
description: A daemon for running Dart builds.
author: Dart Team <[email protected]>
homepage: https://github.com/dart-lang/build/tree/master/build_daemon
Expand Down