86 lines
2.6 KiB
Plaintext
86 lines
2.6 KiB
Plaintext
////////////////////////////////////////////////////////////////////////////////
|
|
//
|
|
// Microsoft Research Singularity
|
|
//
|
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
//
|
|
// File: Getsymlink.sg
|
|
//
|
|
// Note:
|
|
//
|
|
using System;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Threading;
|
|
using Microsoft.Singularity;
|
|
using Microsoft.Singularity.Directory;
|
|
using Microsoft.Singularity.V1.Services;
|
|
using Microsoft.Singularity.Channels;
|
|
|
|
using Microsoft.SingSharp;
|
|
using Microsoft.SingSharp.Runtime;
|
|
|
|
using Microsoft.Contracts;
|
|
using Microsoft.SingSharp.Reflection;
|
|
using Microsoft.Singularity.Applications;
|
|
using Microsoft.Singularity.Io;
|
|
using Microsoft.Singularity.Configuration;
|
|
[assembly: Transform(typeof(ApplicationResourceTransform))]
|
|
|
|
namespace Microsoft.Singularity.Applications {
|
|
[ConsoleCategory(DefaultAction=true)]
|
|
internal class Parameters {
|
|
[InputEndpoint("data")]
|
|
public readonly TRef<UnicodePipeContract.Exp:READY> Stdin;
|
|
|
|
[OutputEndpoint("data")]
|
|
public readonly TRef<UnicodePipeContract.Imp:READY> Stdout;
|
|
|
|
[Endpoint]
|
|
public readonly TRef<DirectoryServiceContract.Imp:Start> nsRef;
|
|
|
|
[StringParameter( "path", Position=0, Mandatory=true)]
|
|
internal string nsPath;
|
|
|
|
reflective internal Parameters();
|
|
|
|
internal int AppMain() {
|
|
return GetSymLink.AppMain(this);
|
|
}
|
|
}
|
|
|
|
class GetSymLink
|
|
{
|
|
private static void tell()
|
|
{
|
|
Console.WriteLine("Getsymlink <link name>.");
|
|
Console.WriteLine(" returns value of link located at <link name>");
|
|
}
|
|
|
|
internal static int AppMain(Parameters! config)
|
|
{
|
|
|
|
ErrorCode errorOut;
|
|
string link;
|
|
|
|
DirectoryServiceContract.Imp ds = (config.nsRef).Acquire();
|
|
if (ds == null) {
|
|
throw new Exception("Unable to acquire handle to the Directory Service root");
|
|
}
|
|
ds.RecvSuccess();
|
|
|
|
bool ok = SdsUtils.GetLinkValue(config.nsPath, ds, out link, out errorOut);
|
|
|
|
if (!ok) {
|
|
Console.WriteLine("{0} ({1}) failed. reason: {2}\n",
|
|
"getsymlink", config.nsPath, SdsUtils.ErrorCodeToString(errorOut) );
|
|
delete ds;
|
|
return -1;
|
|
}
|
|
|
|
Console.WriteLine("Link: {0} -> {1}", config.nsPath,link);
|
|
delete ds;
|
|
return 0;
|
|
}
|
|
}//SymbolicLink
|
|
}//namespace
|