Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Conversation

@Anipik
Copy link

@Anipik Anipik commented Jul 13, 2018

@Anipik Anipik requested review from danmoseley and stephentoub July 13, 2018 05:06
@stephentoub stephentoub changed the title Fix Granularity for copy operation on unix [release/2.1] Fix Granularity for copy operation on unix Jul 13, 2018
[Fact]
public void CopyToMillisecondPresent()
{
FileInfo input = new FileInfo(Path.Combine(TestDirectory, GetTestFileName()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can use GetTestFilePath(): it does the Path.Combine of the TestDirectory with GetTestFileName().

input.Create().Dispose();

string driveFormat = new DriveInfo(input.DirectoryName).DriveFormat;
if (!driveFormat.Equals(HFS, StringComparison.InvariantCultureIgnoreCase))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're going to skip this test on HFS, it'd be better to make this a ConditionalFact that's only executed when the drive format != HFS. (And if for some reason we choose not to do that, the above file creation should be moved to within this if block... there's no benefit to creating the file if we're not going to use it.)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will this be okay

private static bool isHFS = new DriveInfo(Path.GetTempPath()).DriveFormat.Equals(HFS, StringComparison.InvariantCultureIgnoreCase);

// not support millisecond granularity.

// If it's 1/1000, or low granularity, this may help:
Thread.Sleep(1234);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just Thread.Sleep(1)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't sure what the lowest granularity was for all the file systems this might run on. It only happens 1/1000 times, of course.

// If it's 1/1000, or low granularity, this may help:
Thread.Sleep(1234);
input = new FileInfo(Path.Combine(TestDirectory, GetTestFileName()));
input.Create().Dispose();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just call input.Create().Dispose() again on the original input FileInfo?

input.Create().Dispose();
}

FileInfo output = new FileInfo(Path.Combine(TestDirectory, GetTestFileName(), input.Name));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same GetTestFilePath comment.

output = input.CopyTo(output.FullName, true);

Assert.NotEqual(0, input.LastWriteTime.Millisecond);
Assert.NotEqual(0, output.LastWriteTime.Millisecond);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be better to check that Assert.Equal(input.LastWriteTime, output.LastWriteTime)?

Copy link
Author

@Anipik Anipik Jul 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't go for that in order for the test fail if for some reason the millisecond granularity is not working. if we go go for equality. the test will still pass if they are zero

FileInfo output = new FileInfo(Path.Combine(TestDirectory, GetTestFileName(), input.Name));

string driveFormat = new DriveInfo(input.DirectoryName).DriveFormat;
if (driveFormat.Equals(HFS, StringComparison.InvariantCultureIgnoreCase))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar ConditionalFact comment. Or if you don't want to use a ConditionalFact, you can just combine the two tests, with one if branch for if it's on HFS, and an else for if it's not.

@Anipik
Copy link
Author

Anipik commented Jul 13, 2018

@dotnet-bot test NETFX x86 Release Build

@Anipik
Copy link
Author

Anipik commented Jul 17, 2018

@danmosemsft when can we merge this one ?

@danmoseley danmoseley added this to the 2.1.x milestone Jul 17, 2018
@danmoseley danmoseley added the Servicing-consider Issue for next servicing release review label Jul 17, 2018
@danmoseley
Copy link
Member

We are going to sit on this until we see customer impact.

@danmoseley danmoseley added the * NO MERGE * The PR is not ready for merge yet (see discussion for detailed reasons) label Jul 17, 2018
@Anipik
Copy link
Author

Anipik commented Jul 19, 2018

@danmosemsft can you take a look at the formatting done to the test so that we can merge after that (As it has been approved)

{
public class FileInfo_GetSetTimes : InfoGetSetTimes<FileInfo>
{
private static bool isHFS => new DriveInfo(Path.GetTempPath()).DriveFormat.Equals(HFS, StringComparison.InvariantCultureIgnoreCase);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed DriveFormat does not work in AppContainer. I was going to put up a PR to fix that
https://github.com/dotnet/corefx/compare/master...danmosemsft:fix.for.uap?expand=1

I suggest waiting until that's in then pulling that into this PR. The branch isn't open yet anyway

…31164)

* Feedback Addressed

* Fixing original tests and for appContainers

* comment corrected
@Anipik
Copy link
Author

Anipik commented Jul 25, 2018

@dotnet-bot test OSX x64 Debug Build

@danmoseley danmoseley merged commit 83ac6fa into dotnet:release/2.1 Aug 28, 2018
@danmoseley danmoseley modified the milestones: 2.1.x, 2.1.5 Sep 13, 2018
@danmoseley danmoseley added Servicing-approved Approved for servicing release and removed Servicing-approved Approved for servicing release Servicing-approved-2.1.5 labels Sep 13, 2018
@Anipik Anipik deleted the releaseFixTest branch February 26, 2019 19:30
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-System.IO Servicing-approved Approved for servicing release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants