Skip to content

Commit f514b39

Browse files
committed
DataLakeStore - Remove ShouldContinue from adls overwrites
1 parent 91cb4e3 commit f514b39

File tree

5 files changed

+25
-64
lines changed

5 files changed

+25
-64
lines changed

src/ResourceManager/DataLakeStore/Commands.DataLakeStore/Commands/ExportAzureRmDataLakeStoreItem.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,11 @@ public override void ExecuteCmdlet()
8686

8787
FileType type;
8888
ConfirmAction(
89-
Force.IsPresent,
90-
string.Format(Resources.OverwriteFileMessage, powerShellReadyPath),
9189
VerbsData.Export,
9290
Path.TransformedPath,
9391
() =>
9492
{
95-
if (
96-
!DataLakeStoreFileSystemClient.TestFileOrFolderExistence(Path.TransformedPath, Account, out type) ||
97-
type != FileType.FILE)
93+
if (!DataLakeStoreFileSystemClient.TestFileOrFolderExistence(Path.TransformedPath, Account, out type))
9894
{
9995
throw new CloudException(string.Format(Resources.InvalidExportPathType, Path.TransformedPath));
10096
}
@@ -113,8 +109,7 @@ public override void ExecuteCmdlet()
113109
}
114110

115111
WriteObject(powerShellReadyPath);
116-
},
117-
() => File.Exists(powerShellReadyPath));
112+
});
118113
}
119114
}
120115
}

src/ResourceManager/DataLakeStore/Commands.DataLakeStore/Commands/GetAzureRmDataLakeStoreItemContent.cs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -65,22 +65,24 @@ public FileSystemCmdletProviderEncoding Encoding
6565

6666
public override void ExecuteCmdlet()
6767
{
68-
long fileLength = 0;
69-
byte[] byteArray;
70-
fileLength = (long)DataLakeStoreFileSystemClient.GetFileStatus(Path.TransformedPath, Account).Length - Offset;
71-
7268
ConfirmAction(
73-
Force.IsPresent,
74-
Resources.LargeDownloadWarning,
7569
Resources.DownloadFileDataMessage,
7670
Path.TransformedPath,
7771
() =>
7872
{
79-
using (
80-
var memStream =
81-
((MemoryStream)
82-
DataLakeStoreFileSystemClient.PreviewFile(Path.TransformedPath, Account, Length, Offset,
83-
CmdletCancellationToken, this)))
73+
byte[] byteArray;
74+
if (Length <= 0)
75+
{
76+
Length = (long)DataLakeStoreFileSystemClient.GetFileStatus(Path.TransformedPath, Account).Length - Offset;
77+
if (Length > 1 * 1024 * 1024 && !Force)
78+
// If content is greater than 1MB throw an error to the user to let them know they must pass in a length to preview this much content
79+
{
80+
throw new InvalidOperationException(string.Format(Resources.FilePreviewTooLarge, 1 * 1024 * 1024, Length));
81+
}
82+
}
83+
84+
using (var memStream = ((MemoryStream)DataLakeStoreFileSystemClient.PreviewFile(Path.TransformedPath, Account, Length, Offset,
85+
CmdletCancellationToken, this)))
8486
{
8587
byteArray = memStream.ToArray();
8688
}
@@ -93,8 +95,7 @@ public override void ExecuteCmdlet()
9395
{
9496
WriteObject(BytesToString(byteArray, Encoding));
9597
}
96-
},
97-
() => Length <= 0 && fileLength > 1*1024*1024);
98+
});
9899
}
99100
}
100101
}

src/ResourceManager/DataLakeStore/Commands.DataLakeStore/Commands/ImportAzureRmDataLakeStoreItem.cs

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,11 @@ public override void ExecuteCmdlet()
9797
Account,
9898
powerShellSourcePath,
9999
CmdletCancellationToken,
100-
PerFileThreadCount,
101100
ConcurrentFileCount,
101+
PerFileThreadCount,
102102
Recurse,
103103
Force,
104-
Resume, ForceBinary, ForceBinary, this);
104+
Resume, ForceBinary, ForceBinary, cmdletRunningRequest: this);
105105
}
106106
else if (File.Exists(powerShellSourcePath))
107107
{
@@ -114,45 +114,13 @@ public override void ExecuteCmdlet()
114114
Force,
115115
Resume,
116116
ForceBinary,
117-
this);
117+
cmdletRunningRequest: this);
118118
}
119119
else
120120
{
121-
throw new FileNotFoundException(string.Format(Resources.FileOrFolderDoesNotExist,
122-
powerShellSourcePath));
121+
throw new FileNotFoundException(string.Format(Resources.FileOrFolderDoesNotExist, powerShellSourcePath));
123122
}
124123

125-
if (Directory.Exists(powerShellSourcePath))
126-
{
127-
DataLakeStoreFileSystemClient.CopyDirectory(
128-
Destination.TransformedPath,
129-
Account,
130-
powerShellSourcePath,
131-
CmdletCancellationToken,
132-
ConcurrentFileCount,
133-
PerFileThreadCount,
134-
Recurse,
135-
Force,
136-
Resume, ForceBinary, ForceBinary, cmdletRunningRequest: this);
137-
}
138-
else if (File.Exists(powerShellSourcePath))
139-
{
140-
DataLakeStoreFileSystemClient.CopyFile(
141-
Destination.TransformedPath,
142-
Account,
143-
powerShellSourcePath,
144-
CmdletCancellationToken,
145-
PerFileThreadCount,
146-
Force,
147-
Resume,
148-
ForceBinary,
149-
cmdletRunningRequest: this);
150-
}
151-
else
152-
{
153-
throw new FileNotFoundException(string.Format(Resources.FileOrFolderDoesNotExist, powerShellSourcePath));
154-
}
155-
156124
// only attempt to write output if this cmdlet hasn't been cancelled.
157125
if (!CmdletCancellationToken.IsCancellationRequested && !Stopping)
158126
{

src/ResourceManager/DataLakeStore/Commands.DataLakeStore/Commands/JoinAzureRmDataLakeStoreItem.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,8 @@ public override void ExecuteCmdlet()
5555
FileType fileType;
5656
if (ShouldProcess(Destination.TransformedPath, "Join"))
5757
{
58-
if ((DataLakeStoreFileSystemClient.TestFileOrFolderExistence(Destination.TransformedPath, Account,
59-
out fileType) && fileType == FileType.FILE)
60-
&& (Force.IsPresent || ShouldContinue(string.Format(Resources.OverwriteFileMessage, Destination.TransformedPath), "")))
58+
if (Force.IsPresent && (DataLakeStoreFileSystemClient.TestFileOrFolderExistence(Destination.TransformedPath, Account,
59+
out fileType) && fileType == FileType.FILE))
6160
// If it is a directory you are trying to overwrite with a concatenated file, we will error out.
6261
{
6362
DataLakeStoreFileSystemClient.DeleteFileOrFolder(Destination.TransformedPath, Account, false);

src/ResourceManager/DataLakeStore/Commands.DataLakeStore/Commands/MoveAzureRmDataLakeStoreItem.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,13 @@ public override void ExecuteCmdlet()
5555
if (ShouldProcess(Destination.TransformedPath, VerbsCommon.Move))
5656
{
5757
FileType fileType;
58-
if (DataLakeStoreFileSystemClient.TestFileOrFolderExistence(Destination.TransformedPath, Account,
59-
out fileType)
60-
&& (Force.IsPresent || ShouldContinue(string.Format(Resources.OverwriteFileMessage, Destination.TransformedPath), "")))
58+
if (Force.IsPresent && DataLakeStoreFileSystemClient.TestFileOrFolderExistence(Destination.TransformedPath, Account,
59+
out fileType))
6160
{
6261
DataLakeStoreFileSystemClient.DeleteFileOrFolder(Destination.TransformedPath, Account, true);
6362
}
6463

65-
if (
66-
!DataLakeStoreFileSystemClient.RenameFileOrDirectory(Path.TransformedPath, Account,
64+
if (!DataLakeStoreFileSystemClient.RenameFileOrDirectory(Path.TransformedPath, Account,
6765
Destination.TransformedPath))
6866
{
6967
throw new CloudException(

0 commit comments

Comments
 (0)