We are using the following to write a file to the temp direcotry in Azure webapp for almost a year:
string tempName = Path.GetTempFileName();
using (var tempFile = new FileStream(tempName, FileMode.Create))
{
await tempMemory.CopyToAsync(tempFile);
}
We encounter a problem of IOException of file alreay exists in the temp file.
Is there any way deleting the files from that temp directory and not from code. we do not want to apply a new code version currently, but just to somehow delete the files from the temp directory.
we tried using the azure webapp console from the portal but it didn't delete them.
Restart the WebApp, it will clear the temp directory.
Related
I am attempting to deploy a Lambda function using Terraform, where my source files are in a different directory adjacent to where I have my Terraform files. I want to have Terraform do the zipping of the source files for me and deploy them into the Lambda. Terraform doesn't seem to want to recognize that my files are there, though.
My directory structure:
project_root/
deployment/
terraform/
my-terraform.tf
function_source/
function.py
I want it to package everything in function_source directory (there is only one file there now, but may be more later) and drop it into the deployment directory.
My Terraform:
data "archive_file" "lambda_zip" {
type = "zip"
output_path = "../function.zip"
source_dir = "../../function_source/"
}
resource "aws_lambda_function" "my_lambda" {
filename = "${data.archive_file.lambda_zip.output_path}"
function_name = "my-function"
role = "${aws_iam_role.lambda_role.arn}"
handler = "function.handler"
runtime = "python3.7"
}
When I run this, though, I get the error message data.archive_file.lambda_zip: data.archive_file.lambda_zip: error archiving directory: could not archive missing directory: ../../function_source/
I have tried using absolute paths without success (which wouldn't be a good solution anyway). I have also tried creating the .zip file manually and hardcoding its directly in Lambda declaration, but it only works if I put the .zip file in my terraform directory. It seems Terraform can only see files in its own directory or below, but I'd rather not co-mingle my source files there. Is there a way to do this?
I am using Terraform v0.12.4
I want to create a script to sync files between two directories, and was going to utilise Dirsync and Python 3 for this.
from dirsync import sync
sync('C:/03py/Sync/Sync1','C:/03py/Sync/Sync2','sync', twoway=True, create=True)
After running the file for the first time, the folders are synced. I then put a dummy file and folder into the target directory and reran the above script, hoping the file and folder would be copied back into the source directory. However I get the following:
Only in C:/03py/Sync/Sync2
<< TESTTWOFOLDER
<< _TESTTWOWAY.txt
I am not certain if I am using the above commands correctly.
i don't know if this helps...
from dirsync import sync
source_path = 'C:\\wamp\\www\\first-python-app\\http'
target_path = 'C:\\wamp\\www\\first-python-app\\dev'
sync(target_path, source_path, 'sync', twoway=True, purge=True)
sync(source_path, target_path, 'sync')
I'm trying to create a folder within the temp folder that doesn't have a random name.
Here is how I was trying to create the folder within the temp folder.
if not DirExists(ExpandConstant('{%tmp}\Utilities\SDK')) then
CreateDir(ExpandConstant('{%tmp}\Utilities\SDK'));
Log('Temp\Utilities\SDK Folder Has Been Created.');
I had a look at this thread, but even with the %, unfortunately, it still doesn't create the folder.The script compiles and runs as expected, however the folder doesn't create even though it says it has in the log file, I understand that the log file will say that because its told too, however, if the folder was unable to be created, wouldnt it crash? or return a false if an if statement was present?
With CreateDir() You must create dirs one after the other and not a dir structure at once.
if not DirExists(ExpandConstant('{tmp}\Utilities')) then
CreateDir(ExpandConstant('{tmp}\Utilities'));
if not DirExists(ExpandConstant('{tmp}\Utilities\SDK')) then
CreateDir(ExpandConstant('{tmp}\Utilities\SDK'));
if DirExists(ExpandConstant('{tmp}\Utilities\SDK')) then
Log('Temp\Utilities\SDK Folder Has Been Created.') else
Log('Temp\Utilities\SDK Folder ERROR : NOT Created.');
Inno Setup has a function to create a dir structure at once
function ForceDirectories(Dir: string): Boolean;
Example:
if not DirExists(ExpandConstant('{tmp}\Utilities\SDK')) then
ForceDirectories(ExpandConstant('{tmp}\Utilities\SDK'));
Also keep in mind :
{tmp} all is related to the Inno Setup Temp folder is-XXXXX.tmp
C:\Users\...\AppData\Local\Temp\is-XXXXX.tmp
{%temp} is the users Temp folder
C:\Users\...\AppData\Local\Temp
I think you want the Windows Temp and not the tmp from InnoSetup
{tmp}:
Temporary directory used by Setup or Uninstall. This is not the value of the user's TEMP environment variable. It is a subdirectory of the user's temporary directory which is created by Setup or Uninstall at startup (with a name like "C:\WINDOWS\TEMP\IS-xxxxx.tmp"). All files and subdirectories in this directory are deleted when Setup or Uninstall exits. During Setup, this is primarily useful for extracting files that are to be executed in the [Run] section but aren't needed after the installation.
So I think you want to do somethink like this:
if not DirExists(ExpandConstant('{%temp}\Utilities\SDK')) then
CreateDir(ExpandConstant('{%temp}\Utilities\SDK'));
Log('Temp\Utilities\SDK Folder Has Been Created.');
I have a project which is in an Azure Service Fabric Solution. How can I get specific full filepath of a content file? The content file is in the same folder with my source code.
What I tried:
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location
But it turns out:
C:\SfDevCluster\Data_App_Node_4\ABCXYZType_App126\ABCXYZPkg.Code.1.0.0\ABCXYZ.dll
This is a file in bin/debug folder
To get the location of content files you can use:
var path = Path.Combine(
FabricRuntime.GetActivationContext().GetCodePackageObject("Code").Path,
"Readme.txt");
ServiceEventSource.Current.ServiceMessage(this.Context, File.ReadAllText(path));
provided that the file Readme.txt has the Build Action is set to "Content" and the Copy to Output Directory setting is set to something else than "do not copy".
I need to zip some files in amazon s3 without needing to write them to file locally first. Ideally my code worked in development but i don't have many write privileges in production.
folder = output_dir
files = fs.glob(folder)
f = BytesIO()
zip = zipfile.ZipFile(f, 'a', zipfile.ZIP_DEFLATED)
for file in files:
filename = os.path.basename(file)
image = fs.get(file, filename)
zip.write(filename)
zip.close()
the proplem is at this line in production
image = fs.get(file, filename)
Because i don't have write privileges.
My last resort is to write to /tmp/ directory which i have privileges to.
Is there a way to zip files from a url path or directly in the cloud?
I ended up using python tempfile which ended up being a perfect solution.
Using NamedTemporaryFile gave me the guarantee to create named and system visible temporary files that could be deleted automatically. No manual work.