Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 38b1223

Browse files
[[ Bug 12192 ]] Fixes Linux file's permission when creating one with 'url'
Refactors the enum kMCSystemFileMode and kMCSOpenFileMode into one single enum
1 parent 85652eb commit 38b1223

38 files changed

Lines changed: 192 additions & 179 deletions

docs/notes/bugfix-12192.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# linux uninstaller needs execute permission

engine/src/capsule.cpp

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ bool MCCapsuleFillFromFile(MCCapsuleRef self, MCStringRef p_path, uint32_t p_off
299299
t_stream = nil;
300300
if (t_success)
301301
{
302-
t_stream = MCS_open(p_path, kMCSOpenFileModeRead, True, False, 0);
302+
t_stream = MCS_open(p_path, kMCOpenFileModeRead, True, False, 0);
303303
if (t_stream == nil)
304304
t_success = false;
305305
}

engine/src/deploy.cpp

100644100755
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,13 +215,13 @@ bool MCDeployWriteCapsule(const MCDeployParameters& p_params, MCDeployFileRef p_
215215
// Open the stackfile.
216216
MCDeployFileRef t_stackfile;
217217
t_stackfile = NULL;
218-
if (t_success && !MCDeployFileOpen(p_params . stackfile, kMCSOpenFileModeRead, t_stackfile))
218+
if (t_success && !MCDeployFileOpen(p_params . stackfile, kMCOpenFileModeRead, t_stackfile))
219219
t_success = MCDeployThrow(kMCDeployErrorNoStackfile);
220220

221221
// Open the spill file, if required
222222
MCDeployFileRef t_spill;
223223
t_spill = NULL;
224-
if (t_success && !MCStringIsEmpty(p_params . spill) && !MCDeployFileOpen(p_params . spill, kMCSOpenFileModeCreate, t_spill))
224+
if (t_success && !MCStringIsEmpty(p_params . spill) && !MCDeployFileOpen(p_params . spill, kMCOpenFileModeCreate, t_spill))
225225
t_success = MCDeployThrow(kMCDeployErrorNoSpill);
226226

227227
// First create our deployment capsule
@@ -257,7 +257,7 @@ bool MCDeployWriteCapsule(const MCDeployParameters& p_params, MCDeployFileRef p_
257257
{
258258
MCValueRef t_val;
259259
/* UNCHECKED */ MCArrayFetchValueAtIndex(p_params.auxillary_stackfiles, i + 1, t_val);
260-
if (t_success && !MCDeployFileOpen((MCStringRef)t_val, kMCSOpenFileModeRead, t_aux_stackfiles[i]))
260+
if (t_success && !MCDeployFileOpen((MCStringRef)t_val, kMCOpenFileModeRead, t_aux_stackfiles[i]))
261261
t_success = MCDeployThrow(kMCDeployErrorNoAuxStackfile);
262262
if (t_success)
263263
t_success = MCDeployCapsuleDefineFromFile(t_capsule, kMCCapsuleSectionTypeAuxillaryStack, t_aux_stackfiles[i]);
@@ -350,7 +350,7 @@ bool MCDeployWritePayload(const MCDeployParameters& p_params, bool p_to_network,
350350
// First try to open the payload file
351351
MCDeployFileRef t_payload;
352352
t_payload = nil;
353-
if (t_success && !MCDeployFileOpen(p_params . payload, kMCSOpenFileModeRead, t_payload))
353+
if (t_success && !MCDeployFileOpen(p_params . payload, kMCOpenFileModeRead, t_payload))
354354
t_success = MCDeployThrow(kMCDeployErrorNoPayload);
355355

356356
// Next measure the file to find out how big it is

engine/src/deploy_file.cpp

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ bool MCDeployFileOpen(MCStringRef p_path, intenum_t p_mode, MCDeployFileRef& r_f
127127
return false;
128128

129129
IO_handle t_handle ;
130-
if (p_mode == kMCSOpenFileModeCreate)
130+
if (p_mode == kMCOpenFileModeCreate)
131131
t_handle = MCS_deploy_open(p_path, p_mode);
132132
else
133133
t_handle = MCS_open(p_path, p_mode, false, false, 0);

engine/src/deploy_linux.cpp

100644100755
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -659,9 +659,9 @@ Exec_stat MCDeployToELF(const MCDeployParameters& p_params, bool p_is_android)
659659
// First thing we do is open the files.
660660
MCDeployFileRef t_engine, t_output;
661661
t_engine = t_output = NULL;
662-
if (t_success && !MCDeployFileOpen(p_params . engine, kMCSOpenFileModeRead, t_engine))
662+
if (t_success && !MCDeployFileOpen(p_params . engine, kMCOpenFileModeRead, t_engine))
663663
t_success = MCDeployThrow(kMCDeployErrorNoEngine);
664-
if (t_success && !MCDeployFileOpen(p_params . output, kMCSOpenFileModeCreate, t_output))
664+
if (t_success && !MCDeployFileOpen(p_params . output, kMCOpenFileModeCreate, t_output))
665665
t_success = MCDeployThrow(kMCDeployErrorNoOutput);
666666

667667
// Now read in the main ELF header
@@ -900,7 +900,7 @@ Exec_stat MCDeployToLinux(const MCDeployParameters& p_params)
900900

901901
MCDeployFileRef t_engine;
902902
t_engine = NULL;
903-
if (t_success && !MCDeployFileOpen(p_params . engine, kMCSOpenFileModeRead, t_engine))
903+
if (t_success && !MCDeployFileOpen(p_params . engine, kMCOpenFileModeRead, t_engine))
904904
t_success = MCDeployThrow(kMCDeployErrorNoEngine);
905905

906906
char t_ident[EI_NIDENT];

engine/src/deploy_macosx.cpp

100644100755
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1685,12 +1685,12 @@ Exec_stat MCDeployToMacOSX(const MCDeployParameters& p_params)
16851685
MCDeployFileRef t_engine, t_engine_ppc, t_engine_x86, t_output;
16861686
t_engine = t_engine_ppc = t_engine_x86 = t_output = NULL;
16871687
if (t_success &&
1688-
((!MCStringIsEmpty(p_params . engine) && !MCDeployFileOpen(p_params . engine, kMCSOpenFileModeRead, t_engine)) ||
1689-
(!MCStringIsEmpty(p_params . engine_ppc) && !MCDeployFileOpen(p_params . engine_ppc, kMCSOpenFileModeRead, t_engine_ppc)) ||
1690-
(!MCStringIsEmpty(p_params . engine_x86) && !MCDeployFileOpen(p_params . engine_x86, kMCSOpenFileModeRead, t_engine_x86))))
1688+
((!MCStringIsEmpty(p_params . engine) && !MCDeployFileOpen(p_params . engine, kMCOpenFileModeRead, t_engine)) ||
1689+
(!MCStringIsEmpty(p_params . engine_ppc) && !MCDeployFileOpen(p_params . engine_ppc, kMCOpenFileModeRead, t_engine_ppc)) ||
1690+
(!MCStringIsEmpty(p_params . engine_x86) && !MCDeployFileOpen(p_params . engine_x86, kMCOpenFileModeRead, t_engine_x86))))
16911691
t_success = MCDeployThrow(kMCDeployErrorNoEngine);
16921692

1693-
if (t_success && !MCDeployFileOpen(p_params . output, kMCSOpenFileModeCreate, t_output))
1693+
if (t_success && !MCDeployFileOpen(p_params . output, kMCOpenFileModeCreate, t_output))
16941694
t_success = MCDeployThrow(kMCDeployErrorNoOutput);
16951695

16961696
// MW-2013-06-13: If we have a single engine, process that in the appropriate
@@ -1826,11 +1826,11 @@ Exec_stat MCDeployToIOS(const MCDeployParameters& p_params, bool p_embedded)
18261826
MCDeployFileRef t_engine, t_output;
18271827
t_engine = t_output = NULL;
18281828
if (t_success &&
1829-
((MCStringIsEmpty(p_params . engine)) || !MCDeployFileOpen(p_params . engine, kMCSOpenFileModeRead, t_engine)))
1829+
((MCStringIsEmpty(p_params . engine)) || !MCDeployFileOpen(p_params . engine, kMCOpenFileModeRead, t_engine)))
18301830
t_success = MCDeployThrow(kMCDeployErrorNoEngine);
18311831

18321832
// Make sure we can open the output file.
1833-
if (t_success && !MCDeployFileOpen(p_params . output, kMCSOpenFileModeCreate, t_output))
1833+
if (t_success && !MCDeployFileOpen(p_params . output, kMCOpenFileModeCreate, t_output))
18341834
t_success = MCDeployThrow(kMCDeployErrorNoOutput);
18351835

18361836
// Generate the binary.
@@ -2435,10 +2435,10 @@ Exec_stat MCDeployDietMacOSX(const MCDeployDietParameters& p_params)
24352435
// First thing we do is open the files.
24362436
MCDeployFileRef t_engine, t_output;
24372437
t_engine = t_output = NULL;
2438-
if (t_success && !MCDeployFileOpen(p_params . input, kMCSOpenFileModeRead, t_engine))
2438+
if (t_success && !MCDeployFileOpen(p_params . input, kMCOpenFileModeRead, t_engine))
24392439
t_success = MCDeployThrow(kMCDeployErrorNoEngine);
24402440

2441-
if (t_success && !MCDeployFileOpen(p_params . output, kMCSOpenFileModeWrite, t_output))
2441+
if (t_success && !MCDeployFileOpen(p_params . output, kMCOpenFileModeWrite, t_output))
24422442
t_success = MCDeployThrow(kMCDeployErrorNoOutput);
24432443

24442444
// Next we count the number of architectures that we will be including in
@@ -2577,7 +2577,7 @@ Exec_stat MCDeployExtractMacOSX(MCStringRef p_filename, MCStringRef p_segment, M
25772577
// First thing we do is open the input file.
25782578
MCDeployFileRef t_input;
25792579
t_input = NULL;
2580-
if (t_success && !MCDeployFileOpen(p_filename, kMCSOpenFileModeRead, t_input))
2580+
if (t_success && !MCDeployFileOpen(p_filename, kMCOpenFileModeRead, t_input))
25812581
t_success = MCDeployThrow(kMCDeployErrorNoEngine);
25822582

25832583
// Next just run the callback to get the offset of the section within the

engine/src/deploy_sign.cpp

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1050,7 +1050,7 @@ bool MCDeploySignWindows(const MCDeploySignParameters& p_params)
10501050
// First open input and output executable files
10511051
MCDeployFileRef t_input;
10521052
t_input = nil;
1053-
if (t_success && !MCDeployFileOpen(p_params . input, kMCSOpenFileModeRead, t_input))
1053+
if (t_success && !MCDeployFileOpen(p_params . input, kMCOpenFileModeRead, t_input))
10541054
t_success = MCDeployThrow(kMCDeployErrorNoEngine);
10551055

10561056
BIO *t_output;

engine/src/deploy_windows.cpp

100644100755
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,7 @@ static bool MCWindowsResourcesAddIcon(MCWindowsResources& self, MCStringRef p_ic
773773
MCDeployFileRef t_icon;
774774
t_icon = NULL;
775775
if (t_success)
776-
t_success = MCDeployFileOpen(p_icon_file, kMCSOpenFileModeRead, t_icon);
776+
t_success = MCDeployFileOpen(p_icon_file, kMCOpenFileModeRead, t_icon);
777777

778778
// Next read the header - care here to ensure correct structure size
779779
ICONDIR t_dir;
@@ -1223,7 +1223,7 @@ static bool MCWindowsResourcesAddManifest(MCWindowsResources& self, MCStringRef
12231223
MCDeployFileRef t_manifest;
12241224
t_manifest = NULL;
12251225
if (t_success)
1226-
t_success = MCDeployFileOpen(p_manifest_path, kMCSOpenFileModeRead, t_manifest);
1226+
t_success = MCDeployFileOpen(p_manifest_path, kMCOpenFileModeRead, t_manifest);
12271227

12281228
// Measure the manifest
12291229
uint32_t t_size;
@@ -1640,9 +1640,9 @@ Exec_stat MCDeployToWindows(const MCDeployParameters& p_params)
16401640
// First thing to do is to open the files.
16411641
MCDeployFileRef t_engine, t_output;
16421642
t_engine = t_output = NULL;
1643-
if (t_success && !MCDeployFileOpen(p_params . engine, kMCSOpenFileModeRead, t_engine))
1643+
if (t_success && !MCDeployFileOpen(p_params . engine, kMCOpenFileModeRead, t_engine))
16441644
t_success = MCDeployThrow(kMCDeployErrorNoEngine);
1645-
if (t_success && !MCDeployFileOpen(p_params . output, kMCSOpenFileModeCreate, t_output))
1645+
if (t_success && !MCDeployFileOpen(p_params . output, kMCOpenFileModeCreate, t_output))
16461646
t_success = MCDeployThrow(kMCDeployErrorNoOutput);
16471647

16481648
// First load the headers we need

engine/src/dispatch.cpp

100644100755
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ static bool attempt_to_loadfile(IO_handle& r_stream, MCStringRef& r_path, const
426426
va_end(t_args);
427427

428428
IO_handle t_trial_stream;
429-
t_trial_stream = MCS_open(*t_trial_path, kMCSOpenFileModeRead, True, False, 0);
429+
t_trial_stream = MCS_open(*t_trial_path, kMCOpenFileModeRead, True, False, 0);
430430

431431
if (t_trial_stream != nil)
432432
{
@@ -801,7 +801,7 @@ IO_stat MCDispatch::loadfile(MCStringRef p_name, MCStack *&sptr)
801801
t_found = false;
802802
if (!t_found)
803803
{
804-
if ((stream = MCS_open(p_name, kMCSOpenFileModeRead, True, False, 0)) != NULL)
804+
if ((stream = MCS_open(p_name, kMCOpenFileModeRead, True, False, 0)) != NULL)
805805
{
806806
// This should probably use resolvepath().
807807
if (MCStringGetCharAtIndex(p_name, 0) != PATH_SEPARATOR
@@ -827,7 +827,7 @@ IO_stat MCDispatch::loadfile(MCStringRef p_name, MCStack *&sptr)
827827
/* UNCHECKED */ MCStringCopySubstring(p_name, MCRangeMake(t_leaf_index + 1, MCStringGetLength(p_name) - (t_leaf_index + 1)), &t_leaf_name);
828828
else
829829
t_leaf_name = p_name;
830-
if ((stream = MCS_open(*t_leaf_name, kMCSOpenFileModeRead, True, False, 0)) != NULL)
830+
if ((stream = MCS_open(*t_leaf_name, kMCOpenFileModeRead, True, False, 0)) != NULL)
831831
{
832832
MCAutoStringRef t_curpath;
833833
/* UNCHECKED */ MCS_getcurdir(&t_curpath);
@@ -936,7 +936,7 @@ IO_stat MCDispatch::dosavestack(MCStack *sptr, const MCStringRef p_fname)
936936
}
937937
IO_handle stream;
938938

939-
if ((stream = MCS_open(*t_linkname, kMCSOpenFileModeWrite, True, False, 0)) == NULL)
939+
if ((stream = MCS_open(*t_linkname, kMCOpenFileModeWrite, True, False, 0)) == NULL)
940940
{
941941
MCresult->sets("can't open stack file");
942942
cleanup(stream, *t_linkname, *t_backup);

engine/src/dsklnx.cpp

Lines changed: 44 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -932,9 +932,9 @@ class MCLinuxDesktop: public MCSystemInterface
932932

933933
MCshellcmd = strclone("/bin/sh");
934934
#endif /* MCS_init_dsk_lnx */
935-
IO_stdin = MCsystem -> OpenFd(0, kMCSOpenFileModeRead);
936-
IO_stdout = MCsystem -> OpenFd(1, kMCSOpenFileModeWrite);
937-
IO_stderr = MCsystem -> OpenFd(2, kMCSOpenFileModeWrite);
935+
IO_stdin = MCsystem -> OpenFd(0, kMCOpenFileModeRead);
936+
IO_stdout = MCsystem -> OpenFd(1, kMCOpenFileModeWrite);
937+
IO_stderr = MCsystem -> OpenFd(2, kMCOpenFileModeWrite);
938938

939939
// Internally, LiveCode assumes sorting orders etc are those of en_US.
940940
// Additionally, the "native" string encoding for Linux is ISO-8859-1
@@ -1583,7 +1583,7 @@ class MCLinuxDesktop: public MCSystemInterface
15831583

15841584
virtual IO_handle DeployOpen(MCStringRef p_path, intenum_t p_mode)
15851585
{
1586-
if (p_mode != kMCSOpenFileModeCreate)
1586+
if (p_mode != kMCOpenFileModeCreate)
15871587
return OpenFile(p_path, p_mode, False);
15881588

15891589
FILE *fptr;
@@ -1654,7 +1654,7 @@ class MCLinuxDesktop: public MCSystemInterface
16541654
MCAutoStringRefAsSysString t_path_sys;
16551655
/* UNCHECKED */ t_path_sys.Lock(p_path);
16561656

1657-
if (p_map && MCmmap && p_mode == kMCSOpenFileModeRead)
1657+
if (p_map && MCmmap && p_mode == kMCOpenFileModeRead)
16581658
{
16591659
int t_fd = open(*t_path_sys, O_RDONLY);
16601660
struct stat64 t_buf;
@@ -1677,20 +1677,34 @@ class MCLinuxDesktop: public MCSystemInterface
16771677
}
16781678
}
16791679

1680-
const char *t_mode;
1681-
if (p_mode == kMCSOpenFileModeRead)
1682-
t_mode = IO_READ_MODE;
1683-
else if (p_mode == kMCSOpenFileModeWrite)
1684-
t_mode = IO_WRITE_MODE;
1685-
else if (p_mode == kMCSOpenFileModeUpdate)
1686-
t_mode = IO_UPDATE_MODE;
1687-
else if (p_mode == kMCSOpenFileModeAppend)
1688-
t_mode = IO_APPEND_MODE;
1680+
FILE *t_fptr;
1681+
// [[ Bug 12192 ]] We want to create an executable file on Linux
1682+
// when calling OpenFile from MCS_save(binary|text)file
1683+
if (p_mode == kMCOpenFileModeExecutableWrite)
1684+
{
1685+
int t_fd = open(*t_path_sys, O_CREAT | O_TRUNC | O_WRONLY, 0777);
1686+
if (t_fd != -1)
1687+
t_fptr = fdopen(t_fd, "w");
1688+
else
1689+
t_fptr = NULL;
1690+
}
1691+
else
1692+
{
1693+
const char *t_mode;
1694+
if (p_mode == kMCOpenFileModeRead)
1695+
t_mode = IO_READ_MODE;
1696+
else if (p_mode == kMCOpenFileModeWrite)
1697+
t_mode = IO_WRITE_MODE;
1698+
else if (p_mode == kMCOpenFileModeUpdate)
1699+
t_mode = IO_UPDATE_MODE;
1700+
else if (p_mode == kMCOpenFileModeAppend)
1701+
t_mode = IO_APPEND_MODE;
16891702

1690-
FILE *t_fptr = fopen(*t_path_sys, t_mode);
1703+
t_fptr = fopen(*t_path_sys, t_mode);
16911704

1692-
if (t_fptr == NULL && p_mode != kMCSOpenFileModeRead)
1693-
t_fptr = fopen(*t_path_sys, IO_CREATE_MODE);
1705+
if (t_fptr == NULL && p_mode != kMCOpenFileModeRead)
1706+
t_fptr = fopen(*t_path_sys, IO_CREATE_MODE);
1707+
}
16941708

16951709
if (t_fptr != NULL)
16961710
{
@@ -1707,16 +1721,16 @@ class MCLinuxDesktop: public MCSystemInterface
17071721

17081722
switch (p_mode)
17091723
{
1710-
case kMCSOpenFileModeRead:
1724+
case kMCOpenFileModeRead:
17111725
t_fptr = fdopen(p_fd, IO_READ_MODE);
17121726
break;
1713-
case kMCSOpenFileModeWrite:
1727+
case kMCOpenFileModeWrite:
17141728
t_fptr = fdopen(p_fd, IO_WRITE_MODE);
17151729
break;
1716-
case kMCSOpenFileModeUpdate:
1730+
case kMCOpenFileModeUpdate:
17171731
t_fptr = fdopen(p_fd, IO_UPDATE_MODE);
17181732
break;
1719-
case kMCSOpenFileModeAppend:
1733+
case kMCOpenFileModeAppend:
17201734
t_fptr = fdopen(p_fd, IO_APPEND_MODE);
17211735
break;
17221736
}
@@ -1735,16 +1749,16 @@ class MCLinuxDesktop: public MCSystemInterface
17351749
MCAutoStringRefAsSysString t_path_sys;
17361750
/* UNCHECKED */ t_path_sys.Lock(p_path);
17371751

1738-
if (p_mode == kMCSOpenFileModeRead)
1752+
if (p_mode == kMCOpenFileModeRead)
17391753
t_fptr = fopen(*t_path_sys, IO_READ_MODE);
1740-
else if (p_mode == kMCSOpenFileModeWrite)
1754+
else if (p_mode == kMCOpenFileModeWrite)
17411755
t_fptr = fopen(*t_path_sys, IO_WRITE_MODE);
1742-
else if (p_mode == kMCSOpenFileModeUpdate)
1756+
else if (p_mode == kMCOpenFileModeUpdate)
17431757
t_fptr = fopen(*t_path_sys, IO_UPDATE_MODE);
1744-
else if (p_mode == kMCSOpenFileModeAppend)
1758+
else if (p_mode == kMCOpenFileModeAppend)
17451759
t_fptr = fopen(*t_path_sys, IO_APPEND_MODE);
17461760

1747-
if (t_fptr == NULL && p_mode != kMCSOpenFileModeRead)
1761+
if (t_fptr == NULL && p_mode != kMCOpenFileModeRead)
17481762
t_fptr = fopen(*t_path_sys, IO_CREATE_MODE);
17491763

17501764
configureSerialPort((short)fileno(t_fptr));
@@ -2853,12 +2867,12 @@ class MCLinuxDesktop: public MCSystemInterface
28532867
{
28542868
close(toparent[1]);
28552869
MCS_lnx_nodelay(toparent[0]);
2856-
MCprocesses[index].ihandle = OpenFd(toparent[0], kMCSOpenFileModeRead);
2870+
MCprocesses[index].ihandle = OpenFd(toparent[0], kMCOpenFileModeRead);
28572871
}
28582872
if (writing)
28592873
{
28602874
close(tochild[0]);
2861-
MCprocesses[index].ohandle = OpenFd(tochild[1], kMCSOpenFileModeWrite);
2875+
MCprocesses[index].ohandle = OpenFd(tochild[1], kMCOpenFileModeWrite);
28622876
}
28632877
}
28642878
}
@@ -2873,13 +2887,13 @@ class MCLinuxDesktop: public MCSystemInterface
28732887
if (reading)
28742888
{
28752889
MCS_lnx_nodelay(t_input_fd);
2876-
MCprocesses[index] . ihandle = OpenFd(t_input_fd, kMCSOpenFileModeRead);
2890+
MCprocesses[index] . ihandle = OpenFd(t_input_fd, kMCOpenFileModeRead);
28772891
}
28782892
else
28792893
close(t_input_fd);
28802894

28812895
if (writing)
2882-
MCprocesses[index] . ohandle = OpenFd(t_output_fd, kMCSOpenFileModeWrite);
2896+
MCprocesses[index] . ohandle = OpenFd(t_output_fd, kMCOpenFileModeWrite);
28832897
else
28842898
close(t_output_fd);
28852899

0 commit comments

Comments
 (0)